joj 1424 Coin Change(完全背包)

http://acm.jlu.edu.cn/joj/showproblem.php?pid=1424

 

#include <stdio.h>
#include <string.h>

const int coins[6]={0,1,5,10,25,50};

int f[7500];

inline void CompletePack(int w,int total)
{
    for(int j = 1; j <= total; j++)
    {
        if(j >= w) f[j] += f[j-w];
  //      printf("%d ",f[j]);
    }
  //  printf("\n");
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i;
        memset(f,0,sizeof(f));
        f[0] = 1;
        for(i=1; i <= 5; i++) CompletePack(coins[i],n);
        printf("%d\n",f[n]);
    }
    return 0;
}

posted @ 2010-09-02 13:40  菜到不得鸟  阅读(138)  评论(0编辑  收藏  举报