[CF730J]Bottles
题目大意:每个瓶子有一定的容积,以及一定的水量,问最少几个瓶子装满所有水,在此基础上还要最小化移动水的体积
第一问用贪心直接求
第二问转化成背包问题
设dp[i][j]表示前i桶水总容积为j的最多水量,这些水是不需要转移的
用总体积减去最多水量即为答案
代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int x,int y) {return x>y;}
int n,lft,num,tot,ans;
int a[],b[],d[],dp[][];
int main()
{
cin>>n;
for(int i=;i<=n;i++) cin>>a[i],lft+=a[i];
for(int i=;i<=n;i++) cin>>b[i],d[i]=b[i];
sort(d+,d++n,cmp);
memset(dp,,sizeof(dp));
dp[][]=;
for(int i=;i<=n;i++)
{
tot+=d[i];
if(tot>=lft)
{
num=i;
break;
}
}
for(int i=;i<=n;i++)
for(int j=tot;j>=b[i];j--)
for(int k=;k<=num;k++)
dp[k][j]=max(dp[k][j],dp[k-][j-b[i]]+a[i]);
for(int i=lft;i<=tot;i++) ans=max(ans,dp[num][i]);
cout<<num<<" "<<lft-ans<<endl;
return ;
}
[CF730J]Bottles的更多相关文章
- CF 672C Recycling Bottles[最优次优 贪心]
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- codeforces A. Sereja and Bottles 解题报告
题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 贪心
C. Recycling Bottles It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J. Bottles
J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...
- codeforces 352 div 2 C.Recycling Bottles 贪心
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Recycling Bottles 模拟
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 730 j.bottles
J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...
随机推荐
- DNS服务简介
一.域名系统 1.域名系统概述 域名系统DNS(Domain Name System)是因特网使用的命名系统,用来把便于人们使用的机器名字转换成为IP地址.域名系统其实就是名字系统.为什么不叫“名字” ...
- Foj1683矩阵快速幂水题
Foj 1683 纪念SlingShot 题目链接:http://acm.fzu.edu.cn/problem.php?pid=1683 题目:已知 F(n)=3 * F(n-1)+2 * F(n-2 ...
- 修改Android模拟器的system分区,以及加入SuperSU
http://www.claudxiao.net/2013/10/persistent-change-emulator-system-partition/ 对Android的模拟器,如果要修改其s ...
- TCP控制位 sendUrgentData 队列 队列元素 优先级 极限 急停 置顶
Socket (Java Platform SE 7 ) https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#sendUrge ...
- java获取时间段内的所有日期
public static void main(String[] args) { SimpleDateFormat dateFormat = new SimpleDateForm ...
- BitCoin Trading Strategies BackTest With PyAlgoTrade
Written by Khang Nguyen Vo, khangvo88@gmail.com, for the RobustTechHouse blog. Khang is a graduate f ...
- android开发笔记(二)导入项目到eclipse和另一个项目
NND,eclipse里导入工程出现问题了,整了半天,来个这问题,无效工程描述,找了半天看.projec文件是否工程名对应,看androidManifest.XML换里面的代码版本号,我擦都无济于事. ...
- django允许外部访问
默认方法启动django python manage.py runserver 这时启动的服务只能在本机访问,这是因为服务只向本机(127.0.0.1:8000)提供,所以局域网的其他机器不能访问. ...
- 压力测试工具sysbench
sysbench是一个模块化.跨平台.多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用.sysbench主要用于以下性能测试: 文件I/O性能 调度 内存分 ...
- 20165324 《Java程序设计》第九周学习总结
学号 20165324 <Java程序设计>第九周学习总结 教材学习内容总结 第十三章 Java网络编程 URL类 使用URL创建对象的应用程序称为客户端 一个URL对象封装一个具体资源的 ...