Monday, April 4, 2011

674 - Coin Change


#include<stdio.h>
#define M 7489
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("%lld\n",ways[t]);
        else
            printf("%lld\n",ways[t]);
    }
    return 0;
}

No comments:

Post a Comment

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