hdu3602(变形背包)】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3602 题意是:N个国家,M个飞船,每个国家有人数num,如果上飞船就给联合国value钱,选出某些国家上船且每个国家所有人都必须在同一艘船上,使联合国赚得的钱最多,而且被选出的国家上船的顺序必须和原给的国家顺序一致. 分析:dp[M][K]表示第M条船用了容量K的最大价值,O(NMK)的算法行不通 变形:dp[i]表示获得价值i需要花费最少的代价(用了的船位) #include <cstdio>…
P1057 金明的预算方案 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2006 提高组 第二道 描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行”.今天一早,金明就开始做预算了,他把想买的物品分为两类:主件与附件,附件是从属于某个主件的,下表就是一些主件与附件的例子:主件 附件电脑 打印机,扫描仪书柜…
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Hasan has a set of N coins and Bahosain has a set of M coins. The video game costs W JDs. Find the number of ways in which they can pay exactly W JDs su…
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 ],dp[N]; int…
题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大,转而以v为下标,求出价值对应的最小体积,然后求出能够满足给出体积的最大价值. 经典题目,思路倒是挺简单的,就是初始化总觉得别扭...T_T大概,因为我要找的是最小值,所以初始化为maxn,就结了? 这个问题好像叫01背包的超大背包... 模拟一下样例吧! 1 5 15 // 初始化为dp[0] =…
题目链接 分析:完全背包的变形,每一层的d[]数组代表这一层的这个数新加入以后所构成的val的种类. #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cstdlib> #include <algorithm> +; using namespace std; ]; int main() { int n, i, j; w…
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to…
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB In ancient days there was a country whose people had very interesting habits. Some of them were lazy, some were very rich, some were very…
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAXW 15005 #define N 155 #define LL long long #define MOD 1000000007 int w1[N],w2[N]; LL dp1[MAXW],dp2[MAXW]; int main(…
Piggy-Bank   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 557 Accepted Submission(s): 304 Problem Description Before ACM can do anything, a budget must be prepared and the necessary financial s…