Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn't been so wealthy any more. The merchan…
最近,我去了一个古老的国家.在很长一段时间里,它是世界上最富有.最强大的王国.结果,这个国家的人民仍然非常自豪,即使他们的国家不再那么富有.商人是最典型的,他们每个人只卖一件商品,价格是Pi,但是如果你的钱少于Qi,他们就会拒绝和你交易,而我评估每件商品的价值Vi.如果他有M单位的钱,iSea能得到的最大值是多少? 输入 在输入中有几个测试用例.每个测试用例以两个整数N M(1≤N≤500,1≤M≤5000)开始,表示项目编号和初始资金.接着N行,每一行包含3个数字Pi, Qi和Vi(1≤Pi≤…
解法 排序+01背包 这里的排序规则用q-p升序排列这里是一个感觉是一个贪心的策略,为什么这样做目前也无法有效的证明或者说出来 然后就是01背包加了一个体积必须大于什么值可以装那么加一个max(p,q)的条件即可 代码 #include <bits/stdc++.h> using namespace std; struct node { int p,q,w; }num[1000]; bool cmp(node a,node b) { return a.q-a.p<b.q-b.p; } i…
http://acm.hdu.edu.cn/showproblem.php?pid=3466   Description Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4039    Accepted Submission(s): 1677 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1978    Accepted Submission(s): 792 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn't been so wealthy any more. The merchan…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4257    Accepted Submission(s): 1757 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 2674    Accepted Submission(s): 1109 Problem Description Recently, iSea…
题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,dp过程中记录每个容量所能获得的最大价值以及剩余的容量.实现是,开个二维dp数组,从左往右扫,考虑背包容量为j的可获得价值量,根据该剩余容量得知要更新后面哪个背包容量[j+?] ,如果剩余容量大于q[i]那么可以直接装进去,更新价值以及剩余容量,否则,考虑更新的是更大的背包容量.这个思路有缺陷,一直找…
题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are…
HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国家的人民仍然非常自豪. 商人是最典型的,他们每一个只卖了一个项目,价格是PI,但他们拒绝与你交易如果你的钱低于QI,ISEA评估每一个项目的价值VI. 如果他有M单位的钱,伊萨能得到的最大价值是多少? 解题思路 p代表需要的价钱,q代表买这个物品的门槛. 思路就是先尝试买qi-pi大的商品,即按照q…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3466 题意:假设你有M元,已经Pi,Qi,Vi(i为角标,1<i<N),当M>Qi,时才能购买该商品,得到价值Vi,问得到的最大的价值. 思路:知道是变形的01背包问题,但是思考了很久不知道怎么解决,于是看了好几种不同款式的大佬的代码和证明才看懂,如下是自己写的证明: 如果不改变,直接用01背包的话呢,就是: for(int i=0;i<n;i++) for(int j=v;j>=a…
也是好题,带限制的01背包,先排序,再背包 这题因为涉及到q,所以不能直接就01背包了.因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],…,dp[m],再对第二个进行背包的时候,如果是普通的,应该会借用前面的dp[8],dp[7]之类的,但是现在这些值都是0,所以会导致结果出错.于是要想到只有后面要用的值前面都可以得到,那么才不会出错.设A:p1,q1 B:p2,q2,如果先A后B,则至少需要p1+q2的容量,如果先B后A,至少需要p2+q1的容量…
题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are…
Proud Merchants Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 12   Accepted Submission(s) : 5 Problem Description Recently, iSea went to an ancient country. For such a long time, it was the mo…
Problem Description Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy a…
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 505 #define nn 505*100 using namespace std;…
题目http://acm.hdu.edu.cn/showproblem.php?pid=3466 分析:这个题目增加了变量q 因此就不能简单是使用01背包了. 网上看到一个证明: 因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],-,dp[m], 再对第二个进行背包的时候,如果是普通的,应该会借用前面的dp[8],dp[7]之类的 但是现在这些值都是0,所以会导致结果出错. 于是要想到只有后面要用的值前面都可以得到,那么才不会出错. 设A:p1,q1…
I - Proud Merchants Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Description Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the…
给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表示差额最小的为最优.优先考虑放入这个物品 然后01背包计算 #include "stdio.h" #include "string.h" #include "algorithm" using namespace std; int inf=0x3f3f…
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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466 与顺序有关的01背包. 如果一个物品p = 5,q = 7,一个物品p = 5,q = 9,如果先算第一个,那么当次只有7,8...m可以进行状态转移,装第二个物品的时候9,10..m进行转移,第二个物品转移就可以借用第一个物品的那些个状态,而第二个物品先转移,第一个再转移则不能.当然,还有价格有关,当限制一样价格不同时顺序就影响结果.一种组合的排序策略--限制又小价格又贵的先选,也就是q-p…
题目传送门 Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 7536    Accepted Submission(s): 3144 Problem Description Recently, iSea went to an ancient country. For such a long time, i…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4500    Accepted Submission(s): 1873 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能超过背包的容量1-P. 在这个条件下,让装入背包的物品的总价值,也就是bag[i].[v]的和最大 bag.v是每一件物品的价值,bag.p是每件物品的体积 像上面这样想是行不通的.下面有解释 这道题麻烦的是概率这东西没法用个循环表示出来,根据我以往的经验,指望着把给出的测试数据乘上一百或者一万这种…
Magina Problem Description Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of the Ancient).If you have no idea of him, here is some brief introduction of his legendary antecedents:Twin sons to the great Prophet, Terrorblade and…
分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意购买菜,即∑p - max_p +5 <= m  时,re = m - ∑p 2.当余额不充足时,有一种特殊情况,不能消费的情况,即m<5时    re = m; 3.余额不足时,只能购买部分菜,转化成01背包问题,找出最接近最接近5的值, 状态转换方程: f[0][P] = true;f[0][…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有各自的体积和价值.在不超过总体积v的情况下,问能够达到的最大价值.并且物品是一个一个放入的.最后若有剩余的体积也不会填满. 刚开始是用贪心做的.将价值与体积的比值设定为一个值,即单位价值.然后按照单位价值排序,挨个取物品,考虑到了体积为0的情况,就将单位价值设定为无穷大.但是这样做并不能保证最优解.…
http://acm.hdu.edu.cn/showproblem.php?pid=5887 题意: 容量很大的01背包. 思路: 因为这道题目背包容量比较大,所以用dp是行不通的.所以得用搜索来做,但是需要一些剪枝,先按体积排序,优先考虑体积大的物品,这样剪枝会剪得多一些(当然按照性价比排序也是可以的). #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #i…