题目大意:每个瓶子有一定的容积,以及一定的水量,问最少几个瓶子装满所有水,在此基础上还要最小化移动水的体积

第一问用贪心直接求
第二问转化成背包问题
设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的更多相关文章

  1. CF 672C Recycling Bottles[最优次优 贪心]

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. codeforces A. Sereja and Bottles 解题报告

    题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...

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

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

  5. codeforces 352 div 2 C.Recycling Bottles 贪心

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces Recycling Bottles 模拟

    C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...

  7. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  8. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. codeforces 730 j.bottles

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

随机推荐

  1. 在R语言中封装类读写sql操作工具类

    1.mysql_helper.R # 使用RMySQL操作数据库 # 载入DBI和RMySQL包 library(DBI) library(RMySQL) mysql_con <- functi ...

  2. 运用JS设置cookie、读取cookie、删除cookiev

    JS设置cookie: 假设在A页面中要保存变量username的值("jack")到cookie中,key值为name,则相应的JS代码为: document.cookie=&q ...

  3. Quartz.net 基于配置的调度程序实践

    1.Nuget 搜索并安装Quartz.net 2.3.3  2.添加配置到App.config <?xml version="1.0" encoding="utf ...

  4. Bootstrap CSS组组件架构的设计思想

    w AO模式 Append Overwrite 附加重写

  5. Sparrow - Distributed, Low Latency Scheduling

    http://www.cs.berkeley.edu/~matei/papers/2013/sosp_sparrow.pdf http://www.eecs.berkeley.edu/~keo/tal ...

  6. 数字货币量化分析报告_20170905_P

    [分析时间]2017-09-05 16:36:46 [数据来源]中国比特币 https://www.chbtc.com/ef4101d7dd4f1faf4af825035564dd81聚币网 http ...

  7. vue下登录页背景图上下空白处自适应等高

    遇到需求,登录页面需要顶部和底部上下等高,并且随着浏览器自适应上下高度. 解决方法: vue界面的data中先定义 data() { return { windowHeight: "&quo ...

  8. Ansible安装过程中常遇到的错误(FAQ)

    1.安装完成后允许命令报错 Traceback (most recent call last): File , in <module> (runner, results) = cli.ru ...

  9. Linux 下的同步机制

    2017-03-10 回想下最初的计算机设计,在单个CPU的情况下,同一时刻只能由一个线程(在LInux下为进程)占用CPU,且2.6之前的Linux内核并不支持内核抢占,当进程在系统地址运行时,能打 ...

  10. 深入浅出地,彻彻底底地理解python中的编码

    python处理文本的功能非常强大,但是如果是初学者,没有搞清楚python中的编码机制,也经常会遇到乱码或者decode error.本文的目的是简明扼要地说明python的编码机制,并给出一些建议 ...