hdu 1114 基础完全背包】的更多相关文章

题意:给一个储钱罐,已知空的储钱罐和装了硬币的储钱罐的质量.然后给了n种硬币的质量和价值. 问储钱罐里最少有多少钱. 解法:完全背包.注意要初始化为 INF,要正好装满,如果结果是INF,输出This is impossible. #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue&g…
题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <cmath> #incl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 思路:求出存钱罐装全部装满情况下硬币的最小数量,即求出硬币的最小价值.转换为最小背包的问题. #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; int dp[INF],val[INF],we[INF]; int main(void) { int t,n,i,j,m,…
http://acm.hdu.edu.cn/showproblem.php?pid=1114 完全背包的题目,要求输出最小价值.然后一定要把给出的背包重量全部用完. 就是问一个背包为k的大小,n件物品,能装的最小价值,并且一定是用了k个背包容量. 用dp[i]表示背包容量为i得时候,能收录的最小价值, 边界:dp[0] = 0: 没容量,啥都干不了 else dp[i] = inf.一开始初始化为无穷大. 转移的话,dp[i] = min(dp[i], dp[i - weight[j]] + v…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 AC code: #include<bits/stdc++.h> using namespace std; int main() { int c; scanf("%d",&c); while(c--) { ],w[]; scanf("%d%d%d",&e,&f,&n); ; i<n; i++) scanf(&quo…
Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action come…
完全背包模板题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define inf 0x3f3f3f3f ],v[],f[]; int main() { int T,v1,v2,n; scanf("%d",&T); while(T--){ scanf("%d%d",&v1,&v2); scanf(&q…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32061 Accepted Submission(s): 15931 Problem Description Before ACM can do anything, a budget must be prepared and the necessary financial…
Piggy-Bank Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any smal…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16255    Accepted Submission(s): 8192 Problem Description Before ACM can do anything, a budget must be prepared and the necessary finan…