<背包>solution_CF366C_Dima and Salad】的更多相关文章

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 two…
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 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…
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 题意 有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的背包里放,可以取得的…
<题目链接> 题目大意: 在一个水果篮里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出来一些做一个水果沙拉, 并且要求他的水果沙拉的美味度是卡路里的k倍,问小明是否可以做出这么一个水果沙拉,若不能输出-1,否则输出复合要求的最大的美味值. 解题思路: 题目的限制条件为物品的价值总和与卡路里的比值要为K,这个控制,于是我们将卡路里总和乘到的右边,然后移项,可得(a1-k*b1)+(a2-k*b2)+……+(an-k*bn)=0.因此就将 (ai-k*bi…
http://codeforces.com/contest/366/problem/C 题意:给出n个水果的两种属性a属性和b属性,然后挑选苹果,选择的苹果必须要满足这样一个条件:,现在给出n,k,要你求满足这种条件的苹果a属性之和最大,如果找不到,输出-1. 思路:是dp题目,倒是给我提醒比较大.这个题目是可以转化的,转为  所有(aj-k*bj)之和,然后对于任意一个苹果,就是挑与不挑的关系,很明显的背包问题. 对于任意一个苹果,如果选择它,则是dp[v-(aj-k*bj)]+aj,不选择它…
题意:n件东西,有属性a和属性b.要选取若干件东西,使得\(\frac{\sum a_j}{\sum b_j} = k\).在这个条件下,问\(\sum a_j\)最大是多少. 分析:可以将其转化为0-1背包,令\(c[i] = a[i] - k*b[i]\) 等价于物品的重量,\(a_i\)为物品的价值.因为\(c[i]\)可能小于0,所以用\(dp1[i]\)表示重量为正i时的最大收益,\(dp2[i]\)表示负i时的最大收益.最后求\(dp1[i]+dp2[i]\)的最大值就是答案,注意不…
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…
题目链接:http://codeforces.com/problemset/problem/366/C 题意: 有n个物品,每个物品有两个属性a[i]和b[i]. 给定k,让你选出一些物品,使得 ∑ a[i] / ∑ b[i] = k. 问你选出物品的 ∑ a[i]最大是多少. 题解: 将原式变形: ∑ a[i] - k * ∑ b[i] = 0 可以看做有一个容积为0的箱子,每个物品的价值为a[i],体积为a[i] - k*b[i],问你最大总价值. 这就变成了01背包. 但是体积a[i] -…