hdu1114】的更多相关文章

今天广州下雨啦,不过没关系啦,反正我最近也都在刷题学习算法. 昨天做了五题01背包,今天还是背包,不过是完全背包,估计做动态规划要持续好一段时间,一开始选了一道简单题目啦. HDU1114,看了小一段时间,动手打代码,测调后感觉很NICE,交上去就WA了. 后来,是我的MAX值给得太小了.果断加两个零,马上就A掉了. 完全背包的思路和01背包很相似,就是在循环时候有点不同. 01背包的是: memset(dp,0,sizeof(dp)); memset(v,0,sizeof(v)); memse…
1.题目来源HDU1114 Sample Input 3 10 110 2 1 1 30 50 10 110 2 1 1 50 30 1 6 2 10 3 20 4 Sample Output The minimum amount of money in the piggy-bank is 60. The minimum amount of money in the piggy-bank is 100. This is impossible. 2.题目分析 题目首先给定一个空存钱罐的重量和这个存…
题意:给出钱罐的重量,然后是每种钱的价值和重量,问钱罐里最少可能有多少钱. 完全背包. 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; ],w[]; ]; int main() { int T; cin>>T; while(T--) { int m1,m2…
链接:Piggy-Bank 大意:已知一只猪存钱罐空的时候的重量.现在的重量,已知若干种钱的重量和价值,猪里面装着若干钱若干份,求猪中的钱的价值最小值. 题解: DP,完全背包. g[j]表示组成重量j的最小花费 g[j]=min(g[j],g[j-w[i]]+v[i]) 完全背包物品可以多次使用,所以j的循环要正着来. 代码: #include<cstdio> #include<cmath> #include<iostream> #include<cstring…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8039    Accepted Submission(s): 4031 Problem DescriptionBefore ACM can do anything, a budget must be prepared and the necessary financi…
link:http://acm.hdu.edu.cn/showproblem.php?pid=1114 只不过求得是最小值.没什么可说的,连我都会做……o(╯□╰)o /* ID: zypz4571 LANG: C++ TASK: pig.cpp */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #incl…
Piggy-Bank Problem Description 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…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1114 完全背包 题意:给出小猪钱罐的重量和装满钱后的重量,然后是几组数据,每组数据包括每种钱币的价值与重量,要求出重量最少能装满钱罐时的最大价值 #include <string.h> #include <stdio.h> #include <algorithm> #include <iostream> using namespace std; int f[1000…
完全背包的水题,不过今天才学动态规划,就这样啦……hahahah!!! 完全背包跟普通背包的区别是普通背包从后往前循环,以防止被替换 完全背包是从前往后循环,后面的状态会跟着之前状态的改变而改变…… #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <cstdlib> #define…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 分析:很裸的一道完全背包题,只是这里求装满背包后使得价值最少,只需初始化数组dp为inf:dp[0]=0; 然后直接套入完全背包循环就行了... #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #incl…