Code: Select all
#include <iostream>
#include <stdio.h>
#include <map>
#include <string.h>
#include <queue>
using namespace std;
long long dp[305][13][4];
long long DP(int left,int at,int b)
{
long long ans,now;
ans=0;
int i,j,score,sc;
if(left<0) return 0;
if(at==10)
{
if(b==0)
{
if(left==0) return 1;
return 0;
}
if(b==1)
{
for(i=0;i<11;i++)
{
now=DP(left-i,at+1,0);
ans+=now;
}
}
if(b>1)
{
for(i=0;i<11;i++)
{
if(b==3) sc=i*2;
if(b==2) sc=i;
if(i==10)
{
for(j=0;j<11;j++)
{
score=sc+j;
now=DP(left-score,at+1,0);
ans+=now;
}
continue;
}
for(j=0;j<(11-i);j++)
{
score=sc+j;
now=DP(left-score,at+1,0);
ans+=now;
}
}
}
dp[at][left][b]=ans;
return ans;
}
if(at==11)
{
if(left==0) return 1;
return 0;
}
if(dp[left][at][b]!=(-1))
return dp[left][at][b];
ans=0;
for(i=0;i<11;i++)
{
if(b==3)
sc=i*3;
if(b==2 || b==1)
sc=i*2;
if(b==0)
sc=i;
if(i==10)
{
if(b==3 || b==2)
now=DP(left-sc,at+1,3);
if(b==1 || b==0)
now=DP(left-sc,at+1,2);
ans+=now;
continue;
}
for(j=0;j<(11-i);j++)
{
if(b>1) score=sc+j*2;
else score=sc+j;
if((i+j)!=10)
now=DP(left-score,at+1,0);
if((i+j)==10)
now=DP(left-score,at+1,1);
ans+=now;
}
}
dp[left][at][b]=ans;
return ans;
}
int main()
{
long long ans;
int s;
// freopen("a.out","w",stdout);
while(1)
{
scanf("%d",&s);
if(s==(-1))
break;
memset(dp,-1,sizeof(dp));
ans=DP(s,0,0);
printf("%lld\n",ans);
}
return 0;
}