http://codeforces.com/contest/366/problem/C

转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值; 因为a[i]-b[i]*k可以为负数,所以应该分开讨论。结果就是dp[10000],如果等于0则输出-1,否则输出dp[10000];

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 500005
using namespace std; int a[maxn],b[maxn];
int w[maxn];
int dp[maxn];
int n,k; int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int i=; i<=n; i++)
{
scanf("%d",&b[i]);
}
for(int i=; i<=n; i++)
{
w[i]=a[i]-b[i]*k;
}
memset(dp,-,sizeof(dp));
dp[]=;
for(int i=; i<=n; i++)
{
if(w[i]>=)
{
for(int j=; j>=w[i]; j--)
{
if(dp[j-w[i]]!=-)
dp[j]=max(dp[j],dp[j-w[i]]+a[i]);
}
}
else
{
for(int j=; j<; j++)
{
if(dp[j-w[i]]!=-)
dp[j]=max(dp[j],dp[j-w[i]]+a[i]);
}
}
}
if(dp[]==) printf("-1\n");
else printf("%d\n",dp[]);
}
return ;
}

cf C. Dima and Salad的更多相关文章

  1. CF Dima and Salad 01背包

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

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

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

  3. Dima and Salad(完全背包)

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

  4. 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 ...

  5. 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 ...

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

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

  7. Codefroces 366 C Dima and Salad(dp)

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

  8. cf 366C C. Dima and Salad(01背包)

    http://codeforces.com/contest/366/problem/C 题意:给出n个水果的两种属性a属性和b属性,然后挑选苹果,选择的苹果必须要满足这样一个条件:,现在给出n,k,要 ...

  9. cf D. Dima and Trap Graph

    http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #in ...

随机推荐

  1. 设计模式 ( 十六 ): Mediator中介者模式 -- 行为型

    1.概述 在面向对象的软件设计与开发过程中,根据“单一职责原则”,我们应该尽量将对象细化,使其只负责或呈现单一的职责,即将行为分布到各个对象中. 对于一个模块或者系统,可能由很多对象构成,而且这些对象 ...

  2. [转载]STL map中的一些基本函数

    来源:(http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html) - C++ map的基本操作和使用_Live_新浪博客 Map是c++的一个标准容器 ...

  3. hdu4111 Alice and Bob

    Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. appium 并发测试

    Android并发测试 Appium提供了在一台设备上启动多个Android会话的方案,而这个方案需要你输入不同的指令来启动多个Appium服务来实现. 启动多个Android会话的重要指令包括: - ...

  5. BLOG PLUGINS

    文章分享按钮 (1)加网(JiaThis) (2)百度分享 文章关联推荐 每篇博文下面可以显示你博客中与该篇博文有些关联的几篇文章,也就是智能推荐,一方面可以增加你博文的曝光率和点击率,一方面也可以给 ...

  6. StoryBoard页面联线跳转已经页面之间传参数

    1.选中上图黄色.按住Control 把线拖到要要跳转的页面,寻找show. 2.选中联线.在右边Identifier:随便填入一个标示 3.在按钮点击事件加上如下代码 - (IBAction)but ...

  7. MVC VIEW 时间格式控制

    @Convert.ToDateTime(Model.CheckPatronExclusionResults.RequestTime).ToString("yyyy-MM-dd HH:mm:s ...

  8. Apache https 配置指南

    Windows Apache HTTPS配置创建下面3个目录: C:\Program Files\Apache Group\Apache2\conf\sslC:\Program Files\Apach ...

  9. 通过layout实现可拖拽自动排序的UICollectionView

    文/CenturyGuo(简书作者)原文链接:http://www.jianshu.com/p/8d1bf1838882著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. Translat ...

  10. Netmon: A light-weight network monitor for Windows

    Netmon is a light-weight network monitor that works on Windows operating systems. It provides differ ...