1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <iostream> using namespace std; int L,S; int dp[27][352][27];//[length][total][last element] int res_dp[27][352]; int main() { int kase=1; for(int i=1;i<27;i++) { dp[1][i][i]=1; } for(int i=2;i<=26;i++)//length of the string for(int j=1;j<=351;j++)//sum of all the value for(int k=1;k<=26;k++)//max last ending value for(int ll=1;ll<k;ll++) { dp[i][j][k]+=dp[i-1][j-k][ll]; } for(int i=1;i<=26;i++) for(int j=1;j<=351;j++) for(int k=1;k<=26;k++) res_dp[i][j]+=dp[i][j][k]; while(cin>>L) { cin>>S; if(L+S==0) break; cout<<"Case "<<kase++<<": "; if(L>0 && L<=26 && S>0 && S<=351) cout<<res_dp[L][S]<<"\n"; else cout<<0<<"\n"; } return 0; } |