Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5542
Test instructions: The number of M is found in N, so that reading from left to right is the ascending subsequence. How many kinds are there in a question?
The DP (I,J) represents the total number of scenarios that take the first I position, a length of J, and the last number as a (i).
The update is easier, DP (I,J) =∑ (k=1->j-1) DP (I-1,K), initialize DP (i,1) = 1.
1#include <bits/stdc++.h>2 using namespacestd;3 #defineLowbit (x) x & (-X)4 5 Const intMoD =int(1e9+7);6 Const intMAXN =1010;7 intDP[MAXN][MAXN];8 intA[MAXN], H[MAXN];9 intN, M, hcnt;Ten One intSumintIintx) { A intRET =0; - while(x) { -RET = (ret + dp[i][x])%MoD; theX-=lowbit (x); - } - returnret; - } + - voidUpdateintIintXintk) { + while(x <=N) { ADP[I][X] = (dp[i][x] + k)%MoD; atX + =lowbit (x); - } - } - - intGetIDintx) { - returnLower_bound (H, h+hcnt, X)-h; in } - to intMain () { + //freopen ("in", "R", stdin); - intT, _ =1; thescanf"%d", &T); * while(t--) { $printf"Case #%d:", _++);Panax Notoginsengscanf"%d%d", &n, &m); - for(inti =1; I <= N; i++) { thescanf"%d", &a[i]); +h[i-1] =A[i]; A } theSort (h, h+n); hcnt = Unique (h, h+n)-h; + for(inti =1; I <= N; i++) A[i] = GetID (A[i]) +1; -Memset (DP,0,sizeof(DP)); $ for(inti =1; I <= N; i++) { $ intLo =min (i, m); - for(intj =1; J <= Lo; J + +) { - if(J = =1) { theUpdate (J, A[i],1); - Continue;Wuyi } the intTMP = SUM (J-1, a[i]-1); - Update (J, A[i], TMP); Wu } - } Aboutprintf"%d\n", SUM (m, n)); $ } - return 0; -}
[HDOJ5542] The Battle of Chibi (DP, tree-like array)