2015 Nanyang Ccpc c-the Battle of Chibi DP

Source: Internet
Author: User

C-the Battle of Chibi

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection

No

Description

Cao Cao made up a big army and is going to invade the whole South China. Yu Zhou was worried about it. He thought the only-to-beat Cao Cao is to a spy in Cao Cao ' s army. But all generals and soldiers of the Cao Cao were loyal, it ' s impossible to convince any of the them to betray Cao Cao.

So there are only one-of-a-Zhou, send someone to fake surrender Cao Cao. Gai Huang is selected for this important mission. However, Cao Cao is not easy-to-believe others, so Gai Huang must leak some important information to Cao Cao before Surre Ndering.

Yu Zhou discussed with Gai Huang and worked off N information to being leaked, in happening order. Each of the information is estimated to have AI value in Cao Cao ' s opinion.

Actually, if you leak information with strict increasing value could accelerate making Cao Cao believe you. So Gai Huang decided to leak exact M information with strict increasing value in happening order. In other words, Gai Huang won't change the order of the N information and just select M of them. Find out how many ways Gai Huang could does this.

Inputthe first line of the input gives the number of test cases, T (1≤100). T test Cases follow.

Each test case begins with numbers N (1≤n≤103) and M (1≤m≤n), indicating the number of information and number of Informa tion Gai Huang would select. Then N numbers on a line, the ith number AI (1≤ai≤109) indicates the value in Cao Cao's opinion of the ith information in H Appening order. Outputfor each test case, output one line containing case #x: Y, where x is the test Case number (starting from 1) and Y-is The ways Gai Huang can select the information.

The result is too large, and you need to the output of the result mod by 1000000007 (109+7).Sample Input
23 21 2 33 23 2 1

Sample Output

Case #1:3
Case #2:0
HINT

Test instructions

Give you the number of n, and find out how many ascending sub-sequences with a length of M

Exercises

N^3 would have been a direct force, but it would be tle.

So it's better to use a tree-like array to N^2logn.

Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<queue>#include<map>#include<Set>#include<vector>#include<string>#include<stack>#include<bitset>#defineINF 1000000005#defineEPS 1e-12#definePI ACOs (-1.0)#defineLL Long Longusing namespacestd;Const intMAXN =1005;Const intMoD =1000000007; inlineLong LongRead () {Long Longx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intA[MAXN], B[MAXN], C[MAXN][MAXN], N, m, Dp[maxn][maxn];inlinevoidInit () { for(inti =1; I <= N; i++) {A[i]= B[i] =0;  for(intj =1; J <= N; J + +) Dp[i][j]= C[i][j] =0; }    return;} InlineintLowbit (intx) {    returnX & (-x);} InlinevoidUpdate (intLintPosintkey) {     while(Pos <=N) {C[l][pos]= (C[l][pos] +key);  while(c[l][pos]>=MoD) C[l][pos]-=MoD; POS= pos +Lowbit (POS); }    return;} InlineintSum (intLintPOS) {    inttemp =0;  while(POS) {temp= (temp +C[l][pos]);  while(temp >= MoD) Temp-=MoD; POS= pos-Lowbit (POS); }    returntemp;}intMain () {intT, CAS =0; scanf ("%d", &u);  while(t--) {scanf ("%d%d", &n, &m);        Init ();  for(inti =1; I <= N; i++) {A[i]=read (); //scanf ("%d", &a[i]);B[i] =A[i]; } sort (b+1, B +1+N);  for(inti =1; I <= N; i++) A[i]= Lower_bound (b +1, B +1+ N, a[i])-b; //cout <<-1 << endl;         for(inti =1; I <= N; i++)        {           //cout << a[i] << Endl;dp[i][1] =1;  for(intj =2; J <= I; J + +) Dp[i][j]= Sum (J-1, A[i]-1);  for(intj =1; J <= I; J + +) Update (J, A[i], dp[i][j]); }        Long LongAns =0;  for(inti =1; I <= N; i++) {ans= (ans +dp[i][m]);  while(ans>=MoD) ans-=mod;//% MoD; //cout << dp[i][m] << Endl;} printf ("Case #%d:%lld\n", ++cas, ans); }    return 0;}

2015 Nanyang Ccpc c-the Battle of Chibi DP

Related Article

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.