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

【完全背包】HDU 1284 钱币兑换问题

时间:2016-11-13 16:12:34      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:space   iostream   algorithm   for   out   auth   ring   方法   names   

Problem Description

在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。

Input

每行只有一个正整数N,N小于32768。

Output

对应每个输入,输出兑换方法数。

Sample Input

2934
12553

Sample Output

718831
13137761

Author

SmallBeer(CML)

Source

杭电ACM集训队训练赛(VII)
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 
 8 int dp[33005];
 9 
10 int main()
11 {
12     int i,j,n;
13     memset(dp,0,sizeof(dp));
14     dp[0]=1;
15     for(i=1;i<=3;i++)//3种钱币
16         for(j=i;j<=33000;j++)//完全背包 顺序
17             dp[j]+=dp[j-i];
18     while(~scanf("%d",&n))
19     {
20         printf("%d\n",dp[n]);
21     }
22     return 0;
23 }

 

【完全背包】HDU 1284 钱币兑换问题

标签:space   iostream   algorithm   for   out   auth   ring   方法   names   

原文地址:http://www.cnblogs.com/Annetree/p/6058690.html

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