//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,dp[30][500][30];
int solve(int n,int m,int z){
if(n==0 && m==0)
return 1;
if(n<=0 || m<=0)
return 0;
if(dp[n][m][z]!=-1)
return dp[n][m][z];
int x=0,i;
f(i,1,z)
if(m-i>=0)
x+=solve(n-1,m-i,i);
return dp[n][m][z]=x;
}
int main(){
int r,k,i,c=1,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
while(1){
sii(n,m);
clr(dp,-1);
if(n==0 && m==0)
break;
printf("Case %d: ",c++);
if(n>26 || m>351)
pi(0);
else
pi(solve(n,m,27));
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,dp[30][500][30];
int solve(int n,int m,int z){
if(n==0 && m==0)
return 1;
if(n<=0 || m<=0)
return 0;
if(dp[n][m][z]!=-1)
return dp[n][m][z];
int x=0,i;
f(i,1,z)
if(m-i>=0)
x+=solve(n-1,m-i,i);
return dp[n][m][z]=x;
}
int main(){
int r,k,i,c=1,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
while(1){
sii(n,m);
clr(dp,-1);
if(n==0 && m==0)
break;
printf("Case %d: ",c++);
if(n>26 || m>351)
pi(0);
else
pi(solve(n,m,27));
}
return 0;
}
No comments:
Post a Comment