题意:

  第一类物品的价值为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)的更多相关文章

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

  2. 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表示 ...

  3. 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 题解: 题意 ...

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

  5. 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(){ ...

  6. ZOJ 4019 Schrödinger's Knapsack

    Schrödinger's Knapsack Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid has a magical knap ...

  7. ZOJ - 4019 Schrödinger's Knapsack (背包,贪心,动态规划)

    [传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5747 [题目大意]:薛定谔的背包.薛定谔的猫是只有观测了才知道猫的死 ...

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

  9. zoj4019 Schrödinger's Knapsack(dp)

    题意:有两种物品分别为n,m个,每种物品对应价值k1,k2.有一个容量为c的背包,每次将一个物品放入背包所获取的价值为k1/k2*放入物品后的剩余体积.求问所获取的最大价值. 整体来看,优先放入体积较 ...

随机推荐

  1. 设置开启telnet功能

    今天访问服务器的时候发现ip可以ping通,但是不能访问,就telnet一下端口吧,谁知系统逗我:

  2. linux 脚本统计代码行数

    由于实际需求,需要统计开源产品的代码行数,so,以下命令统计*.c的行数. .h,.java  .同理 find . -name *.c|xargs wc -l

  3. protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object

    使用protobuf出错:protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object ...

  4. 负载均衡LVS

    可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...

  5. [bzoj 3720] Gty的妹子树 (树上分块)

    树上分块(块状树) Description 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕-- Gty神(xian)犇(chong)从来不缺妹子-- 他来到了 ...

  6. Android系统shell中的clear命令实现【转】

    本文转载自:http://blog.csdn.net/morixinguan/article/details/73467845 之前一直不太清楚,当我们在shell命令行输入很多命令,会在屏幕上输出一 ...

  7. POJ 2506 Tiling (递推 + 大数加法模拟 )

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7965   Accepted: 3866 Descriptio ...

  8. Struts2基础知识

    1.什么是Struts2框架? 答:struts2是一款优秀的mvc框架,集中解决了Controlller的相关问题,解决了部分视图相关的问题(struts2标签): mvc 是一种思想,包括Mode ...

  9. php函数的参数引用变量

    在php.ini中将allow_call_time_pass_reference的值改为'on'.

  10. 【转】看C++文档的小知识

    转载:http://www.ggv.com.cn/forum/clib/ctype/isspace.html 函数isspace 原型:extern int isspace(int c);    用法 ...