[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 ...
随机推荐
- CentOS设置PPTP拨号连接远程服务器
本次测试在Ucloud云服务器从香港连接至广州服务器 1,环境及配置查看 2,安装ppp,pptp,pptp-setup包 yum install -y ppp pptp pptp-setup 3,使 ...
- ionic 移动开发性能调优-去除动画
<ion-refresher></ion-refresher> ion-refresher指令有以下可选的属性: on-refresh - 当用户向下拉动足够的距离并松开时,执 ...
- FZU 2140 Forever 0.5(找规律,几何)
Problem 2140 Forever 0.5 Accept: 371 Submit: 1307 Special Judge Time Limit: 1000 mSec Memory Limit : ...
- Enables DNS lookups on client IP addresses
w虚拟域名访问,路由可以到达,但无输出. http://httpd.apache.org/docs/2.2/mod/core.html#hostnamelookups
- webpack4学习笔记(一)
webpack4 1,安装webpack npm insatll webpack --save-dev //安装最新版本 npm insatll webpack@<version> --s ...
- 【python】-- RabbitMQ 队列消息持久化、消息公平分发
RabbitMQ 队列消息持久化 假如消息队列test里面还有消息等待消费者(consumers)去接收,但是这个时候服务器端宕机了,这个时候消息是否还在? 1.队列消息非持久化 服务端(produc ...
- Storm编程模型及组件流程图
一.Storm编程模型 二.Storm组件流程图
- react 获取input标签的输入值
参考:https://segmentfault.com/a/1190000012404114 两种方法,受控组件和非受控组件. 推荐使用受控组件,即通过this.state获取,因为其符合react规 ...
- sql server常用性能计数器
https://blog.csdn.net/kk185800961/article/details/52462913?utm_source=blogxgwz5 https://blog.csdn.ne ...
- android 读取通讯录显示到gridview
........... <GridView android:id="@+id/gridView1" android:layout_width="match_pare ...