ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意:
第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S22,S23,S24.......S2m;
每次装入物品时,得到的价值是 剩余背包体积*该类物品的价值;问最多能得到的总价值是多少。
思路:
要想得到最大的总价值,肯定要从小的开始装,然后分别枚举第一类,第二类装进去的最大体积,还有将两类回合装入背包的最大体积,得到最后的答案
我们用dp[i][j],来表示 1 - i 的第一种物品区间,1 - j 的第二种物品区间,即装入 1到 i 的一类物品和 1 到 j 的二类物品的所得到的最大价值
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = ;
typedef long long ll; int t;
ll dp[maxn][maxn];
ll c1, c2, c;
ll v1[maxn], v2[maxn], sum1[maxn], sum2[maxn]; int main(){
cin >> t;
while (t--){
cin >> c1 >> c2 >> c;
int n, m;
cin >> n >> m; for (int i = ; i <= n; i++)
cin >> v1[i];
for (int i = ; i <= m; i++)
cin >> v2[i]; sort(v1 + , v1 + + n);
sort(v2 + , v2 + + m);
for (int i = ; i <= n; i++)
sum1[i] = sum1[i - ] + v1[i];
for (int i = ; i <= m; i++)
sum2[i] = sum2[i - ] + v2[i]; for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
dp[i][j] = ; ll ans = ;
for (int i = ; i <= n; i++)
if (sum1[i] <= c){
dp[i][] = c1*(c - sum1[i]) + dp[i - ][];
ans = max(ans, dp[i][]);
}
for (int j = ; j <= m; j++)
if (sum2[j] <= c){
dp[][j] = c2*(c - sum2[j]) + dp[][j - ];
ans = max(ans, dp[][j]);
} for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
{
ll cnt = sum1[i] + sum2[j];
if (cnt <= c)
{
dp[i][j] = max(dp[i - ][j] + c1*(c - cnt), dp[i][j - ] + c2*(c - cnt));
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
return ;
}
ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)的更多相关文章
- ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...
- 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...
- zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- ZOJ 4019 Schrödinger's Knapsack
Schrödinger's Knapsack Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid has a magical knap ...
- ZOJ - 4019 Schrödinger's Knapsack (背包,贪心,动态规划)
[传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5747 [题目大意]:薛定谔的背包.薛定谔的猫是只有观测了才知道猫的死 ...
- ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display Time Limit: 1 Second Memory Limit: 65536 KB A seven segment display, or s ...
- zoj4019 Schrödinger's Knapsack(dp)
题意:有两种物品分别为n,m个,每种物品对应价值k1,k2.有一个容量为c的背包,每次将一个物品放入背包所获取的价值为k1/k2*放入物品后的剩余体积.求问所获取的最大价值. 整体来看,优先放入体积较 ...
随机推荐
- (转)windows下一分钟配置ngnix实现HLS m3u8点播
一.首先保证nginx能正常运行: 这个就是因为前面我们把nginx的目录加到了Path中,然而nginx启动时各种路径都是以当前工作目录为起始点的,这就导致了系统去“C:\User ...
- 动态区间第K大
整体二分. 主要需要注意的一点是,对于每个删除操作,若删除操作被算入贡献,则最开始的插入操作也一定会被算入,所以不必担心删除删错. #include<cstdio> #include< ...
- NOIP2010_T4_引水入城 bfs+贪心
在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 N 行 M 列的矩形,如上图所示,其中每个格子都代表一座城 市,每座城市都有一个海拔高度.为了使 ...
- 转载的C#学习笔记
转载地址:http://www.cnblogs.com/renyanlei/p/4075065.html 最近在一个培训机构里面教授Net知识.每天都会带领学生学习c#知识.我希望把每天学习的笔记记录 ...
- .cxx_destruct crash
开发过程中遇到 YXTBaseLabelCell .cxx_destruct崩溃,查了下,会在调用类的dealloc方法时调用cxx_destruct,于是看了下代码,找dealloc可能会崩溃的原因 ...
- js事件传播的一个疑惑
在学习事件传播的时候,发现一个问题,当时是这样子的. 我给多层元素分别绑定了冒泡和捕获事件.按道理应该先从外向内执行完所有的捕获事件,再由内向外执行所有的冒泡事件. 但是天不随人愿啊,有个元素偏偏先执 ...
- Python 黑帽子第二章运行截图
- Preface Numbering
链接 分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可 /* PROB:preface ID:wanghan LANG:C++ */ #include "iostream&qu ...
- Git 常用命令学习
本文转载自:https://buptldy.github.io/2016/03/02/2016-03-02-Git%20Cheat%20Sheet/ 文章 创建版本库 初始化一个Git仓库,使用git ...
- 17.for循环语句
for循环: 语法: for(表达式1;表达式2;表达式3){ java语句; } 表达式1是最初始化表达式:最先执行,只执行一次 表达式2必须是boolean 类型的表达式.结果为ture或者fal ...