[HDOJ5542] The Battle of Chibi (DP, tree-like array)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.