2015 CCPC C题(超时代码)

来源:互联网 发布:瑞珀网络机顶盒升级包 编辑:程序博客网 时间:2024/05/17 08:11

The Battle of Chibi

Time Limit: 6000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

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

So there is only one way left for Yu Zhou, send someone to fake surrender Cao Cao. Gai Huang was selected for this important mission. However, Cao Cao was not easy to believe others,so Gai Huang must leak some important information to Cao Cao before surrendering.

Yu Zhou discussed with Gai Huang and worked out N information to be leaked, in happening order. Each of the information was estimated to hasai 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 exactM information with strict increasingvalue in happening order. In other words, Gai Huang will not change the order of theN information and just select M of them. Find out how many ways Gai Huang could do this.

Input

The first line of the input gives the number of test cases, T(1100).T test cases follow.

Each test case begins with two numbers N(1N103) and M(1MN), indicating the number of information and number of information Gai Huang will select.ThenN numbers in a line, the ith number ai(1ai109) indicates the value in Cao Cao's opinion of the ith information in happening order.

Output

For 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 output the result mod by 1000000007(109+7).

Sample input and output

Sample InputSample Output
23 21 2 33 23 2 1
Case #1: 3Case #2: 0

Hint

In the first cases, Gai Huang need to leak 2 information out of 3. He could leak any 2 information as all the information value are in increasing order. In the second cases,Gai Huang has no choice as selecting any2 information is not in increasing order.

Source

The 2015 China Collegiate Programming Contest


题目大意:给你一个长度为n的数列,问你有多少组长度为m的递增数列;

题目大意很简单,现场赛的时候定义错状态,没能做出来;

定义dp[i][j]表示长度为j,以第i个数结尾的递增序列的组数;

所以状态转移方程不就是if(a[i] > a[k] )  dp[i][j]  += dp[k][j-1];

代码如下(不能够通过的):

#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;long long dp[1005][1005], s[1005];void test_case(){    int n,m;    scanf("%d%d",&n,&m);    for(int i=1; i<=n; i++)        scanf("%d",&s[i]);    memset(dp,0,sizeof(dp));    for(int i=1; i<=n; i++)    {        dp[i][1]=1;        for(int j=1; j<=m; j++)            for(int k=1; k<i; k++)            {                if(s[i] > s[k])                    dp[i][j] += dp[k][j-1];                dp[i][j] %=  1000000007;            }    }    long long ans = 0;    for(int i=1; i<=n; i++)    {        ans += dp[i][m];    }    printf("%lld\n",ans%1000000007);}int main(){    int t;    scanf("%d",&t);    for(int c=1; c<=t; c++)    {        printf("Case #%d: ",c);        test_case();    }    return 0;}
这是n三方的代码,不能够过这题的,博主太弱了,不会优化;
据说要用树状数组求逆序对的思想优化一下,博主这两天正在学习树状数组:

先占坑,待补;


0 0
原创粉丝点击