hdu 5185

Equation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 270    Accepted Submission(s): 78


Problem Description
Gorwin is very interested in equations. Nowadays she gets an equation like this
x1+x2+x3++xn=n , and here
0xinfor1inxixi+1xi+1for1in1

For a certain  n , Gorwin wants to know how many combinations of  xi  satisfies above condition.
For the answer may be very large, you are expected output the result after it modular  m .
 

Input
Multi test cases. The first line of the file is an integer  T  indicates the number of test cases.
In the next  T  lines, every line contain two integer  n,m .

[Technical Specification]
1T<20
1n50000
1m1000000000
 

Output
For each case output should occupies one line, the output format is Case #id: ans, here id is the data number starting from 1, ans is the result you are expected to output.
See the samples for more details.
 

Sample Input
  
  
2 3 100 5 100
 


Sample Output
  
  
Case #1: 2 Case #2: 3

 
<pre name="code" class="cpp">#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

//f[j][i]表示当前放到了第i个(也即使当前总容量为i),并且第i个重量最大为j
int f[320][50010];    //第一维不可太大,否则超内存

int main(){
    int T; scanf("%d",&T);
    for(int cas=1;cas<=T;cas++){
        int n,m;
        scanf("%d%d",&n,&m);

        memset(f,0,sizeof(f));
        f[0][0]=1;
        int k;
        for(int i=1;i<=n;i++){
            k=(int)(sqrt(8*n+1.0)-1)/2;
            for(int j=1;j<=k;j++){
                f[j][i]=(f[j-1][i-j]+f[j][i-j])%m;   //第i个重量可能和第i-1重量相同均为j
            }
        }
        int ans=0;
        for(int i=1;i<=k;i++){
            ans=(ans+f[i][n])%m;
        }
        printf("Case #%d: %d\n",cas,ans);
    }
    return 0;
}


 
 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值