Codeforces 366C Dima and Salad
http://codeforces.com/problemset/problem/366/C
题意:在一个冰箱里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出来一些做一个水果沙拉, 并且要求他的水果沙拉的美味度之和是卡路里和的k倍,问小明是否可以做出这么一个水果沙拉,若不能输出-1,否则输出符合要求的最大的美味值之和。
思路:考虑这样DP:f[i][j]:做到第i个水果,平衡度为j,平衡度的表示:Σa[i]-K*Σb[i],这样就可以dp
f[i][j]=max(f[i-1][j],f[i-1][j-a[i]+K*b[i]])
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int f[][],a[],b[],g[][];
int n,K;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();K=read();
for (int i=;i<=n;i++) a[i]=read();
for (int i=;i<=n;i++) b[i]=read();
for (int i=;i<=n;i++)
for (int j=;j<=;j++)
f[i][j]=-;
f[][]=; int cnt=;
for (int i=;i<=n;i++){
cnt++;
for (int j=-;j<=;j++){
f[i][j+]=std::max(f[i][j+],std::max(f[i-][j+],f[i-][j-a[i]+K*b[i]+]+a[i]));
}
}
int ans=-;
if (f[n][]) ans=f[n][];
printf("%d\n",ans);
return ;
}
Codeforces 366C Dima and Salad的更多相关文章
- Codeforces 366C Dima and Salad:背包dp
题目链接:http://codeforces.com/problemset/problem/366/C 题意: 有n个物品,每个物品有两个属性a[i]和b[i]. 给定k,让你选出一些物品,使得 ∑ ...
- codeforces 366C Dima and Salad 【限制性01背包】
<题目链接> 题目大意: 在一个水果篮里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出来一些做一个水果沙拉, 并且要求他的水果沙拉的美味度是卡路里 ...
- CodeForces - 366C Dima and Salad (01背包)
题意:n件东西,有属性a和属性b.要选取若干件东西,使得\(\frac{\sum a_j}{\sum b_j} = k\).在这个条件下,问\(\sum a_j\)最大是多少. 分析:可以将其转化为0 ...
- 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 ...
- 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 ...
- Dima and Salad(完全背包)
Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF Dima and Salad 01背包
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces-214(Div. 2)-C. Dima and Salad+DP恰好背包花费
codeforces-214(Div. 2)-C. Dima and Salad 题意:有不同的沙拉,对应不同的颜值和卡路里,现在要求取出总颜值尽可能高的沙拉,同时要满足 解法:首先要把除法变成乘法, ...
- Codefroces 366 C Dima and Salad(dp)
Dima and Salad 题意:一共有n种水果,每种水果都有一个ai, bi,现求一个最大的ai总和,使得ai之和/对应的bi之和的值等于K. 题解:将bi转换成偏移量,只要偏移到起点位置,就代表 ...
随机推荐
- puppet cert maintain
- centos Minicom通信终端
minicom是linux下的串口通信软件,他使用完全使用键盘操作.它虽然没有windows下的超级终端好用,但是它也是一种串口通信的方法.一.minicom安装在超级终端中输入:sally@sall ...
- 【绿茶书情】:《SOHO小报》和《凤… - 绿茶的日志 - 网易博客
[绿茶书情]:<SOHO小报>和<凤- - 绿茶的日志 - 网易博客 [绿茶书情]:<SOHO小报>和<凤-
- xm学习笔记
1关于静态网页的制作 html主要负责页面的结构+css页面的美观+js与用户的交互. 2html 有标签体的标签: <p></p> <span></spa ...
- PHP数据结构:栈、队列、堆、固定数组
数据结构:栈 队列: 堆: 固定尺寸的数组:
- C# - List操作- 去掉重复
ChangeList里面会有重复的数据,这时可以这样去掉重复的item // Remove duplicated info var dup = ChangeList.Where(item => ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- Mysql 时间操作
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度) 1 . 查看当天日期 select current_date(); 2. 查看当天时间 select current_time(); ...
- 贪心-hdu-1789-Doing Homework again
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目意思: 有n个作业,每个作业有一个截止日期,每个作业如果超过截止日期完成的时候有一个惩罚值 ...
- work staff
培训一周,很抓狂.不是抓狂培训本身,是自己听不懂,培训还是有用的. 上周四接到一个task,关于checklist.因为组里没有人用过,所以遇到一些问题,本来不应该是一个复杂的工作,但是我需要一个一个 ...