是一个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;
const int maxn=,maxs=2e5+; inline ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} int N,K,a[maxn],b[maxn];
int f[][maxs]; int main(){
int i,j,k;
N=rd(),K=rd();
for(i=;i<=N;i++) a[i]=rd();
for(i=;i<=N;i++) b[i]=rd();
int M=1e5;
CLR(f,-);
f[][M]=;
for(i=;i<=N;i++){
memcpy(f[i&],f[!(i&)],sizeof(f[]));
for(j=;j<=*M;j++){
int v=a[i]-K*b[i];
if(f[!(i&)][j]<) continue;
f[i&][j+v]=max(f[i&][j+v],f[!(i&)][j]+a[i]);
}
}
printf("%d\n",f[N&][M]?f[N&][M]:-);
return ;
}

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

  1. codeforces-214(Div. 2)-C. Dima and Salad+DP恰好背包花费

    codeforces-214(Div. 2)-C. Dima and Salad 题意:有不同的沙拉,对应不同的颜值和卡路里,现在要求取出总颜值尽可能高的沙拉,同时要满足 解法:首先要把除法变成乘法, ...

  2. Codefroces 366 C Dima and Salad(dp)

    Dima and Salad 题意:一共有n种水果,每种水果都有一个ai, bi,现求一个最大的ai总和,使得ai之和/对应的bi之和的值等于K. 题解:将bi转换成偏移量,只要偏移到起点位置,就代表 ...

  3. Codeforces Round #214 (Div. 2) C. Dima and Salad (背包变形)

    C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

    C. Dima and Salad   Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to ...

  5. CF#214 C. Dima and Salad 01背包变形

    C. Dima and Salad 题意 有n种水果,第i个水果有一个美味度ai和能量值bi,现在要选择部分水果做沙拉,假如此时选择了m个水果,要保证\(\frac{\sum_{i=1}^ma_i}{ ...

  6. Dima and Salad(完全背包)

    Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. CF Dima and Salad 01背包

    C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces 366C Dima and Salad:背包dp

    题目链接:http://codeforces.com/problemset/problem/366/C 题意: 有n个物品,每个物品有两个属性a[i]和b[i]. 给定k,让你选出一些物品,使得 ∑ ...

  9. C. Dima and Salad 背包好题

    http://codeforces.com/contest/366/problem/C 在n个物品中选出若干个,使得sum(a[i]) = k * sum(b[i]) 把问题转化一下就是,求sum(a ...

随机推荐

  1. 学习PHPExcel

    关于PHPExcel使用方法,可以参考慕课网的教程,链接在此 PHPExcel的github地址:https://github.com/PHPOffice/PHPExcel 下载之后,将文件夹中的Cl ...

  2. linux下jenkins的时区设置问题

    https://blog.csdn.net/king_wang10086/article/details/76178711 [root@jenkins ~]# yum install -y ntpda ...

  3. jmeter内存溢出解决办法

    原文:http://blog.51cto.com/xqtesting/2107927 使用jmeter进行压力测试时遇到一段时间后报内存溢出outfmenmory错误,导致jmeter卡死了,先尝试在 ...

  4. PreparedStatement 与 Statement 的区别

    1. PreparedStatement 接口继承 Statement, PreparedStatement 实例包含已编译的 SQL 语句,所以其执行速度要快于 Statement 对象. 2.作为 ...

  5. 4 Past progressive VS simple past

    1 一般过去时用来谈论过去开始和结束的活动.过去进行时用来谈论过去正在进行或者发生的活动. Why were you at office so later yesterday? I was worki ...

  6. [转帖]整理:Windows系统下的奇技淫巧大汇总

    整理:Windows系统下的奇技淫巧大汇总 https://blog.csdn.net/bat67/article/details/76381357 Win+home Crtl+home 还有 Win ...

  7. 基于vue-cli,sass,vant的移动端项目

    项目架构 开始 vue init webpack    项目名称         //新建项目,cd进入新项目 npm install axios                    //先安装! ...

  8. 图解Python的直接赋值与浅拷贝和深度拷贝三者区别

    直接赋值:其实就是对象的引用(别名). 浅拷贝(copy):拷贝父对象,不会拷贝对象的内部的子对象. 深拷贝(deepcopy): copy 模块的 deepcopy 方法,完全拷贝了父对象及其子对象 ...

  9. python之路--操作系统介绍,进程的创建

    一 .  操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 二 多道技术: 所谓多道程序设计技术,就是指允许多个程序同时进入内存 ...

  10. 引入kaptcha实现验证码验证

    1.导入jar包, 可以选择去 https://mvnrepository.com 里面搜索,也可以直接复制下面的代码 2.复制到maven配置文件pom.xml中并保存 <dependency ...