cf366C Dima and Salad (dp)】的更多相关文章

是一个01分数规划的形式,只不过已经帮你二分好了. 把b乘过去,再减回来,找和等于0的a的最大值就行了 #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll; ,maxs=2e5+; inline ll rd(){ ll x=;; ;c=getchar();} +c-',c=ge…
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…
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的背包里放,可以取得的…
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…
题目链接: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] -…
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.因为…