题意:找出长度为n的序列中 递增序列长度为m的个数。
分析:dp[i][j] = sum(dp[1][j-1]+dp[2][j-1]+~+dp[i-1][j-1])
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <cstdlib> #include <map> using namespace std; const int Mod = 1000000007; int a[1005]; int b[1005]; int dp[1005][1005]; int sum(int nn, int mm) { int ans=0; while(nn) { ans += dp[nn][mm]; ans%=Mod; nn -= nn&(-nn); } return ans; } void update(int n, int nn, int mm, int x) { while(nn<=n) { dp[nn][mm] += x; dp[nn][mm] %= Mod; nn+=nn&(-nn); } } int main() { int t; int n, m; scanf("%d", &t); for(int tt=1; tt<=t; tt++) { scanf("%d %d", &n, &m); for(int i=1; i<=n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b+1, b+n+1); int k = unique(b+1, b+n+1)-b-1; for(int i=1; i<=n; i++) { a[i] = lower_bound(b+1, b+n+1, a[i])-b; } memset(dp, 0, sizeof(dp)); for(int i=1; i<=n; i++) { for(int j=1; j<=min(i,m); j++) { if(j==1) { update(n, a[i], j, 1); continue; } int x = sum(a[i]-1, j-1); update(n, a[i], j, x); } } int ans = sum(n, m); printf("Case #%d: %d\n", tt, ans); } return 0; }
HDU 5542 The Battle of Chibi (ccpc 南阳 C)(DP 树状数组 离散化)
原文:http://www.cnblogs.com/mengzhong/p/5483182.html