Page 1 of 1

11238:: Why WA? Where is the problem?

Posted: Sun Jul 01, 2012 6:37 am
by sikder1588

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


11238 - Innoumerous bowling games

Posted: Sun Jul 01, 2012 6:38 am
by sikder1588
I am not understanding the problem. Can anyone please explain me??

Re: 11238: Help

Posted: Sun Jul 01, 2012 6:48 am
by sikder1588
If the person gets 10 points in the last frame.
What happens if it is a strike??
What happens if it a spare??

In the last two bonus attempts, its it possible to score 9,8 or sth like this?

Re: 11238: Help

Posted: Mon Jul 02, 2012 10:29 pm
by brianfry713
For each test case, print the number of different bowling games resulting in the given score in one line.

Look up the rules of bowling. The problem statement is clear. In the 10th frame, if you get a strike you get two more attempts. If you get a spare you get one more attempt.

Re: 11238:: Why WA? Where is the problem?

Posted: Mon Jul 02, 2012 10:33 pm
by brianfry713
Doesn't match the sample I/O.