0&1
Description
Input
第一行是一个不超过100的整数t,代表了样例的组数
接下来有多行,每行两个整数n和k,
Output
对于每组输入样例,先输出它的序号标识(‘CASE 1:’, ‘CASE 2:’, etc).
再输出其满足条件的数的个数
Sample Input 1
5
6 3
6 4
6 2
26 3
64 2
Sample Output 1
Case 1: 1
Case 2: 3
Case 3: 6
Case 4: 1662453
Case 5: 465428353255261088
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define ull unsigned long long
using namespace std;
ll dp[66][66][105];
void dis(int a[], int n){
printf("总数为%d个\n",n);
for(int i = 0; i < n; i++) cout<<a[i]<<", ";
cout<<endl<<"------------------"<<endl;
}
const int mx = 0;
int main(){
int T,n,mod;
scanf("%d",&T);
//T = 10;
for(int ca = 1; ca <= T; ca++){
scanf("%d%d",&n,&mod);
memset(dp,0,sizeof(dp));
if(n%2||n== 0||mod==0){
printf("Case %d: %lld\n",ca,0);
continue;
}
/* if(k== 0){
printf("Case %d: %lld\n",0);
continue;
}*/
dp[1][1][1%mod] = 1;
for(int i = 2; i <=n; i++){
for(int j = 0; j <= i; j++){
for(int k = 0; k < mod; k++){
if(i >0&&j>0)
dp[i][j][(k*2+1)%mod] += dp[i-1][j-1][k]; //加1的
if(i >0)
dp[i][j][(k*2)%mod] += dp[i-1][j][k];
}
}
}
// cout<<dp[2][1][0]<<endl;
// ll ans = 0;
printf("Case %d: %lld\n",ca,dp[n][n/2][0]);
//cout<<dp[n][n/2][0]<<endl;
}
return 0;
}