2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest - J. Bottles(DP)
来源:互联网 发布:软件开发项目建议书 编辑:程序博客网 时间:2024/05/19 07:09
分析:f[i][j] 表示当前用了i个瓶子,共堆出来j的容量的最大剩余.
#include<iostream>#include<string>#include<algorithm>#include<cstdlib>#include<cstdio>#include<set>#include<map>#include<vector>#include<cstring>#include<stack>#include<queue>#define INF 4557430888798830400ll#define eps 1e-9#define MAXN 0x3f#define N 105using namespace std;int n,k,ans,tot,tot_b,cnt,a[N],s[N],b[N],f[N][10005]; int main(){scanf("%d",&n);for(int i = 1;i <= n;i++) {scanf("%d",&a[i]);tot += a[i];}for(int i = 1;i <= n;i++) {scanf("%d",&b[i]);s[i] = b[i];tot_b += b[i];}sort(s+1,s+1+n);for(int i = 1;i <= n && cnt < tot;i++){k++;cnt += s[n-i+1];}memset(f,-1,sizeof(f));f[0][0] = 0,ans = tot;for(int i = 1;i <= n;i++) for(int j = tot_b;j >= b[i];j--) for(int l = k;l;l--) if(f[l-1][j-b[i]] >= 0) f[l][j] = max(f[l][j],f[l-1][j-b[i]] + a[i]);for(int j = tot_b;j >= tot;j--) ans = min(ans,tot - f[k][j]);printf("%d %d\n",k,ans); }
0 0
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J Bottles
- Codeforces 730 J. Bottles DP 0-1背包- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest - J. Bottles(DP)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J dp
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J.Bottles(背包,好题)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J Bottle动态规划
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- 2007-2008 ACM-ICPC, NEERC, Southern Subregional Contest J
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J题(BFS)
- CodeForces 589J ——2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest G. Car Repair Shop(优先队列)
- Codeforces 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror)
- codeforces 730G Car Repair Shop 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest A. Toda 2
- Zynq-Linux移植学习笔记之四-fsbl
- C#版-Redis缓存服务器在Windows下的使用
- 使用此Adapter,代码量可大大减少
- C# XML
- nginx模块开发0(hello world)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest - J. Bottles(DP)
- android开发视频
- Python爬虫初试
- 299. Bulls and Cows
- 乐pro3(lex720)评测
- 阿里云ECS下安装jdk1.8
- Taglib标签之六Taglib中常用的属性值与tld常用标签简介与web.xml设置自定义标签的uri
- Android性能优化系列之apk瘦身
- 1013. Battle Over Cities