10912

#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;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *