2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包
2 seconds
512 megabytes
standard input
standard output
Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda from one bottle to another.
Nick asks you to help him to determine k — the minimal number of bottles to store all remaining soda and t — the minimal time to pour soda into k bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of bottles.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the amount of soda remaining in the i-th bottle.
The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the volume of the i-th bottle.
It is guaranteed that ai ≤ bi for any i.
The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.
4
3 3 4 3
4 7 6 5
2 6
2
1 1
100 100
1 1
5
10 30 5 6 24
10 41 7 8 24
3 11
In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it.
题意:给你n个杯子 给出n个杯子的初始水的体积以及杯子的体积 现在倒水 使得用最少个数的杯子装所有的水 并且在倒水的过程中 使得倒出的水尽量的少
题解:爆搜TLE 背包处理 orzzz 太菜了
dp[i][j]表示用i个杯子容量为j最多能装多少水 注意这个j的范围为杯子的体积和 (可能所选的i个杯子 就算装有全部的水 也不会装满)
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
struct node
{
int a,b;
}N[];
int dp[][];
bool cmp(struct node aa,struct node bb)
{
if(aa.b>bb.b)
return true;
if(aa.b==bb.b)
{
if(aa.a>bb.a)
return true;
}
return false;
}
int main()
{
scanf("%d",&n);
int m=;
int mm;
int mm2=;
for(int i=;i<=n;i++)
{
scanf("%d",&N[i].a);
m+=N[i].a;
}
mm=m;
for(int i=;i<=n;i++)
{
scanf("%d",&N[i].b);
mm2+=N[i].b;
}
sort(N+,N++n,cmp);
int num=;
while()
{
m-=N[++num].b;
if(m<=)
break;
}
memset(dp,,sizeof(dp));
for(int i=;i<=num;i++)
for(int j=;j<=mm2;j++)
dp[i][j]=-INF;
dp[][]=;
for(int j=;j<=n;j++)
{
for(int k=mm2;k>=N[j].b;k--)
{
for(int l=;l<=num;l++){
dp[l][k]=max(dp[l][k],dp[l-][k-N[j].b]+N[j].a);
}
}
}
int ans=;
for(int i=mm2;i>=mm;i--)
if(dp[num][i])
ans=max(ans,dp[num][i]);
printf("%d %d\n",num,mm-ans);
return ;
}
/*
10
18 42 5 1 26 8 40 34 8 29
18 71 21 67 38 13 99 37 47 76
3 100
*/
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包的更多相关文章
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
随机推荐
- POJ 1753 Flip Game 状态压缩,暴力 难度:1
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4863 Accepted: 1983 Descript ...
- HDU 1533 KM算法(权值最小的最佳匹配)
Going Home Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1394 树状数组求逆序对
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 常州培训 day5 解题报告
第一题:(贪心) 题目大意:给出N*M的矩形,要用正方形将它铺满(正方形之间不能重叠),相邻的正方形颜色不能相同,颜色用ABCD表示.要求从上到下从左到右字典序最小. N,M<=100 解题过程 ...
- win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
错误一: HTTP Error 500.19 - Internal Server Error配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (ov ...
- main函数参数的使用
int main(int argc, char * argv[]) argc: argument count argv:argument vector 其中, char * argv[] 指针数组 c ...
- sql游标的使用入门
游标的理解: 游标其实可以理解成一个定义在特定数据集上的指针,我们可以控制这个指针遍历数据集,或者仅仅是指向特定的行,所以游标是定义在以Select开始的数据集上的 普通的sql语句是面向集合的,游标 ...
- Format a Hard Drive in Csharp C#格式化总结
using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Management; ...
- Struts2标签<s:textfield/>
中的name="",取值顺序是,如不加#,先从root中栈顶取,没有取到(即使栈顶有这个属性但是属性为空还是向下取,这点和el表达式不同)就去actioncontext的map中取 ...
- JS创建自定义对象
普通对象的创建: 创建对象: 1.people = new Object(); people.name = "lin"; people.age = "26“; 2.创建字 ...