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

第一问用贪心直接求
第二问转化成背包问题
设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. HDU 5877 2016大连网络赛 Weak Pair(树状数组,线段树,动态开点,启发式合并,可持久化线段树)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Tota ...

  2. hdu2254 奥运 矩阵的应用

    hdu2254 奥运 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2254 题意:题目让我们求得是的可以得到的金牌数量,而和金牌数量=在t1到t2天( ...

  3. HTTP Headers Client Identification

    用户信息通过HTTP头部承载:不能实现用户唯一性标识. w HTTP The Definitive Guide Table 11-1 shows the seven HTTP request head ...

  4. 用Python构建你自己的推荐系统

    用Python构建你自己的推荐系统 现如今,网站用推荐系统为你提供个性化的体验,告诉你买啥,吃啥甚至你应该和谁交朋友.尽管每个人口味不同,但大体都适用这个套路.人们倾向于喜欢那些与自己喜欢的其他东西相 ...

  5. zipline风险指标计算 (empyrical模块)

    概述 量化中,我们经常会遇到各种量化指标的计算,对于zipline来说,也会对这部分计算进行处理,由于指标计算的通用性比较强,所以,zipline单独封装了 empyrical 这个模块,可以处理类似 ...

  6. Fibonacci----poj3070(矩阵快速幂, 模板)

    题目链接:http://poj.org/problem?id=3070 . 就是斐波那契的另一种表示方法是矩阵的幂: 所以是矩阵快速幂:矩阵快速幂学习 #include <cstdio> ...

  7. linux定时查询mysql数据库并把结果保存到新表 然后备份数据库

    脚本文件名:myshell内容如下: #!/bin/bash # mysql用户名 username="root" # mysql密码 password="root&qu ...

  8. 一个父亲的教育札记——leo鉴书58

    由于年纪和工作的原因.绝大部分小说我都不看--没空,如今小说写的也太空.但对文笔有提高的文章我是非常关注的,知道韩寒不是由于<三重门>(我报纸也不怎么看).而是此前编辑感觉我文笔差.   ...

  9. 联想yoga table2 1371f 进入bios 的巧妙方法

    win8.1 的平板,无键盘,触屏失灵,接了个鼠标   我在这里向大家介绍最后一个方法<ignore_js_op>▲在metro界面下找到设置选项 <ignore_js_op> ...

  10. django 用户注册功能实现

    增加views的类 class RegisterView(View): def get(self, request): return render(request, 'register.html', ...