C. Dima and Salad 背包好题】的更多相关文章

http://codeforces.com/contest/366/problem/C 在n个物品中选出若干个,使得sum(a[i]) = k * sum(b[i]) 把问题转化一下就是,求sum(a[i] - k * b[i]) = 0的最大的a[i],这个时候已经把a[i]作为价值了 那么怎么去求呢? 一开始因为a[i] - k * b[i]有负数,那么需要fix值,fix = 1000 我只设了dp[v]表示产生这个和值时的最大价值.那么如果能产生这个v值,就需要这个v值能整除fix.因为…
C. Dima and Salad   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 have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has…
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…
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 ha…
C. Dima and Salad 题意 有n种水果,第i个水果有一个美味度ai和能量值bi,现在要选择部分水果做沙拉,假如此时选择了m个水果,要保证\(\frac{\sum_{i=1}^ma_i}{\sum_{i=1}^mb_i}==k\),问沙拉最大的美味度是多少? 思路 01背包变形. 对于给出的公式,我们化简一下: \(\sum_{i=1}^ma_i-k*\sum_{i=1}^mb_i==0\) 就变成了把a[i]-k*b[i]作为体积,a[i]作为价值,向容量为0的背包里放,可以取得的…
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…
codeforces-214(Div. 2)-C. Dima and Salad 题意:有不同的沙拉,对应不同的颜值和卡路里,现在要求取出总颜值尽可能高的沙拉,同时要满足 解法:首先要把除法变成乘法,就是每次把读进来的b[ i ] 乘以 K; 因为对于a [ i ] - b[ i ] * k有两种不同的可能(大于0和小于0),可以放在一个以25000为中心的,大小为50000的dp数组里: 比如对于样例1: input 3 2 10 8 1 2 7 1 output 18这里我们缩小一下数据 我…
Dima and Salad 题意:一共有n种水果,每种水果都有一个ai, bi,现求一个最大的ai总和,使得ai之和/对应的bi之和的值等于K. 题解:将bi转换成偏移量,只要偏移到起点位置,就代表左右偏移抵消了,就满足题意了,注意一点的是这个跑法和01背包的恰好消耗是一样的初始化方法,将起点设为0,其他位置设为-INF,这样状态只能从起点转移出去,然后再从外面存在的点转移出去. 代码: #include<iostream> #include<cstring> using nam…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大价值. 分组背包模版题. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib&g…
背包九讲下载CSDN 背包九讲内容 多重背包: hdu 2191 珍惜现在,感恩生活 多重背包入门题 使用将多重背包转化为完全背包与01背包求解: 对于w*num>= V这时就是完全背包,完全背包为何只与01背包在循环上不同,因为01背包,每个物品只能取一次,所以要逆序:而完全背包,每个物品的数量无限多个,这就需要建在在之前已经取到了当前要取的基础之上: 同时01背包使用二进制优化处理:即使用二进制表示最优的可取值: 二进制优化的技巧:1,2,4,...,2k−1,n[i]−2k +1(循环之外…