码迷,mamicode.com
首页 > 其他好文 > 详细

HDU2069 Coin Change (DP)

时间:2015-01-09 22:20:22      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:hdu   dp   

题目意思:

http://acm.hdu.edu.cn/showproblem.php?pid=2069

给你五种硬币:1,5,10,25,50,现在给出一个n,求出用用这些组成价值n的种类数,例如n=11;

1、11个1

2、1个10,1个1

3、1个5,6个1

4、2个5,1个1

特别注意:使用硬币数不能超过100,只要注意了这个就可以了。


AC代码:

/**
  *@xiaoran
  *dp[i],最多100枚硬币
  */
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define LL long long
using namespace std;
const int a[5]={1,5,10,25,50};
LL dp[255][101];//dp[j][k]:用k个硬币组成j值的个数
int main()
{
    int n;
    while(cin>>n){
        //cout<<res[n]<<endl;
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=0;i<5;i++){
            for(int k=1;k<=100;k++){//k个硬币
                for(int j=a[i];j<=n;j++){
                    dp[j][k]+=dp[j-a[i]][k-1];
                }
            }
        }
        int res=0;
        for(int i=0;i<=100;i++){
            res+=dp[n][i];
        }
        cout<<res<<endl;
    }
	return 0;
}


HDU2069 Coin Change (DP)

标签:hdu   dp   

原文地址:http://blog.csdn.net/fool_ran/article/details/42563151

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!