Monday, April 4, 2011

357 - Let Me Count The Ways


#include<stdio.h>
#define M 30000
long long ways[M+2];

int main()
{
    int coin[]={50,25,10,5,1};
    register int i,j,t;
    //freopen("in.txt","r",stdin);

    ways[0]=1;
    for(i=0;i<5;i++)
        for(j=coin[i];j<=M;j++)
            ways[j]+=ways[j-coin[i]];

    while(scanf("%ld",&t)==1)
    {
        if(ways[t]==1)
            printf("There is only %lld way to produce %d cents change.\n",ways[t],t);
        else
            printf("There are %lld ways to produce %d cents change.\n",ways[t],t);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.