首页 > 代码库 > HDU 1284 钱币兑换问题
HDU 1284 钱币兑换问题
钱币兑换问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9699 Accepted Submission(s): 5898
Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
Input
每行只有一个正整数N,N小于32768。
Output
对应每个输入,输出兑换方法数。
Sample Input
293412553
Sample Output
71883113137761
完全背包。只是统计方案数。
dp[i]代表 组成i的方法数。那么 dp[i]可由dp[i-1],dp[i-2],dp[i-3]转移过来...
/* ***********************************************Author :guanjunCreated Time :2016/12/6 11:36:45File Name :hdu1284.cpp************************************************ */#include <bits/stdc++.h>#define ull unsigned long long#define ll long long#define mod 90001#define INF 0x3f3f3f3f#define maxn 10010#define cle(a) memset(a,0,sizeof(a))const ull inf = 1LL << 61;const double eps=1e-5;using namespace std;priority_queue<int,vector<int>,greater<int> >pq;struct Node{ int x,y;};struct cmp{ bool operator()(Node a,Node b){ if(a.x==b.x) return a.y> b.y; return a.x>b.x; }};bool cmp(int a,int b){ return a>b;}int dp[40000];int main(){ #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int n; dp[0]=1; for(int i=1;i<=3;i++){ for(int j=i;j<=36000;j++) dp[j]+=dp[j-i]; } while(~scanf("%d",&n)){ printf("%d\n",dp[n]); } return 0;}
HDU 1284 钱币兑换问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。