HDU1114 背包】的更多相关文章

Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23354    Accepted Submission(s): 11824 Problem Description Before ACM can do anything, a budget must be prepared and the necessary fina…
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…
今天广州下雨啦,不过没关系啦,反正我最近也都在刷题学习算法. 昨天做了五题01背包,今天还是背包,不过是完全背包,估计做动态规划要持续好一段时间,一开始选了一道简单题目啦. HDU1114,看了小一段时间,动手打代码,测调后感觉很NICE,交上去就WA了. 后来,是我的MAX值给得太小了.果断加两个零,马上就A掉了. 完全背包的思路和01背包很相似,就是在循环时候有点不同. 01背包的是: memset(dp,0,sizeof(dp)); memset(v,0,sizeof(v)); memse…
题意:给出钱罐的重量,然后是每种钱的价值和重量,问钱罐里最少可能有多少钱. 完全背包. 代码: #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…
题目链接: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…
https://vjudge.net/contest/68966#problem/F 初始化就行了:dp[0]=0: 这题还要刚好装满背包,输出时进行判断 #include<map> #include<set> #include<list> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #inc…
题意:已知空钱罐质量和满钱罐质量(也就是知道钱罐里的钱的质量),知道若干种钱币每种的质量以及其价值,钱币都是无限个,问最少钱罐中有多少钱. 这个题在集训的时候学长给我们做过,所以你会做是应该的,由于已经有固定的质量,所以是必须正好放满的完全背包问题.然后```具体过程就不细讲了完全背包依旧是经典,你要是还不会就滚回去看背包九讲并且无颜见学长们了``` #include<stdio.h> #include<string.h> #define min(a,b) a<b?a:b ]…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35043    Accepted Submission(s): 17420 Problem Description Before ACM can do anything, a budget must be prepared and the necessary fina…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19849    Accepted Submission(s): 10086 Problem Description Before ACM can do anything, a budget must be prepared and the necessary fina…
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11149    Accepted Submission(s): 5632 Problem Description Before ACM can do anything, a budget must be prepared and the necessary fina…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27563    Accepted Submission(s): 13934 Problem Description Before ACM can do…
B - 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…
完全背包模板,和01背包相比不用倒推,因为一种可以选多个. 这道题求最小,dp数组初始化为无穷即可. 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int M=10005; 6 const int INF=0x3f3f3f; 7 int dp[M];//dp[j]表示放入重量为j的存钱罐面值之和最小值 8 int val[M],w…
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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目描述: 代码实现: #include<cstdio> #include<iostream> using namespace std; ]; int main() { ],p[]; int T,n,E,F,weight,i,j; scanf("%d",&T); while(T--){ scanf("%d%d",&E,&am…
题目很水,不多说......... #include<stdio.h> int main() { long t,n,m,a,i,j,dp[10005],vol[505],jizhi[505],sum,w; scanf("%ld",&t); while(t--) { w=0; scanf("%ld%ld",&n,&m); sum=m-n; scanf("%ld",&a); for(i=0;i<a;i…
//新手DP学习中 = =!! 前言:背包问题在dp中可以说是经典,作为一个acmer,到现在才正式学习dp,可以说是比较失败的.我个人比较认同一点,想要做一个比较成功的acmer,dp.搜索.数学必须精练,比较遗憾的是,对我我自身而言,并没有早早的认识到这个问题,不过现在知道了,还有一年,也不算晚.还有,我建议学背包的童鞋,都看背包九讲...... dp之01背包 01背包,做为背包中最基础的一类背包,必须要掌握好,当然我这里说的掌握好,并不是说,你横扫hdu或者poj等oj上01背包模板题就…
来源hdu1114 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…
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.题目分析 题目首先给定一个空存钱罐的重量和这个存…
转载请注明出处:http://blog.csdn.net/u012860063 贴一个自觉得解说不错的链接:http://www.cppblog.com/tanky-woo/archive/2010/07/31/121803.html 模版就直接贴代码: 01背包模板: /* 01背包问题 01背包问题的特点是,">每种物品仅有一件.能够选择放或不放. 01背包问题描写叙述: 有N件物品和一个容量为V的背包. 第i件物品的重量是c[i],价值是w[i]. 求解将哪些物品装入背包可使这些物品…
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出dp[j]=min(dp[j],dp[j-a]+1).j从a到k*10000顺序枚举,因为类似于完全背包. http://train.usaco.org/usacoprob2?a=fSgPyIazooa&S=stamps /* TASK:stamps LANG:C++ */ #include<c…
题意:给你n组物品和自己有的价值s,每组有l个物品和有一种类型: 0:此组中最少选择一个 1:此组中最多选择一个 2:此组随便选 每种物品有两个值:是需要价值ci,可获得乐趣gi 问在满足条件的情况下,可以得到的最大的乐趣是多少,如果不能满足条件就输出-1 题解:二维01背包 dp[i][j]:前i组物品我们拥有j的价值时最大可获得的乐趣 0:我们需要先把dp[i]所有赋值为负无穷,这样就只能最少选一个才能改变负无穷 1:我们不需要:dp[i][j-ci]+gi(在此组中再选一个),这样就一定最…
FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12533    Accepted Submission(s): 5932 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级.现在的问…
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some H…
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时候最大的F. 解法: 用DP来做,如果定义dp[i][j]为前 i 个,D值为j的情况下最大的F的话,由于D值可能会增加到很大,所以是存不下的,又因为F每次最多增加20,那么1000次最多增加20000,所以开dp[1000][20000],dp[i][j]表示前 i 个,F值为j的情况下最小的D.…
题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能获得尽量多的收益呢?作为一名大神犇,他轻而易举的解决了这个问题. 然而,就在他出发前,他又收到了一批奇货.这些货共有m件,第i件的价值Yi与分配的体积Xi之间的关系为:Yi=ai*Xi^2+bi*Xi+ci.这是件好事,但小S却不知道怎么处理了,于是他找到了一位超级神犇(也就是你),请你帮他解决这个…
Dominoes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6731   Accepted: 2234 Description A domino is a flat, thumbsized tile, the face of which is divided into two squares, each left blank or bearing from one to six dots. There is a ro…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 5599    Accepted Submission(s): 2362 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   Special Judge Description Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every t…