ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
来源:互联网 发布:黑莓q10软件 编辑:程序博客网 时间:2024/06/06 10:59
There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, …, xm, then his comfort level of the semester can be defined as follows:
Edward, a student in Marjar University, wants to select some courses (also he can select no courses, then his comfort level is 0) to maximize his comfort level. Can you help him?
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains a integer n (1 ≤ n ≤ 500) – the number of cources.
Each of the next n lines contains two integers Hi and Ci (1 ≤ Hi ≤ 10000, 1 ≤ Ci ≤ 100).
It is guaranteed that the sum of all n does not exceed 5000.
We kindly remind you that this problem contains large I/O file, so it’s recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.
Output
For each case, you should output one integer denoting the maximum comfort.
Sample Input
2
3
10 1
5 1
2 10
2
1 10
2 10
Sample Output
191
0
Hint
For the first case, Edward should select the first and second courses.
For the second case, Edward should select no courses.
好灵活的01 背包的题啊,根据C一定,求H的最大值,然后就能求得总的最大值了
#include<cstdio>#include<cstring>#include<stdlib.h>#include<fstream>#include<ctype.h>#include<math.h>#include<stack>#include<queue>#include<map>#include<set>#include<vector>#include<string>#include<iostream>#include<algorithm>#include<utility>#include<iomanip>#include<time.h>#include<iostream>#define lowbit(x) (x&-x)#define abs(x) ((x)>0?(x):-(x))using namespace std;typedef long long ll;const double Pi = acos(-1.0);const int N = 1e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;const double e=2.718281828459 ;const double esp=1e-9;ll t,n,h[505],c[505];ll dp[N];int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); cin>>t; while(t--) { ll sum1=0; memset(dp,0,sizeof(dp)); cin>>n; for(int i=0; i<n;i++) { cin>>h[i]>>c[i]; sum1+=c[i]; } ll sum=0; for(int i=0;i<n;i++) { for(int j=sum1;j>=c[i];j--) { dp[j]=max(dp[j],dp[j-c[i]]+h[i]); } } for(int i=0;i<=sum1;i++) { sum=max(sum,(ll)dp[i]*dp[i]-(ll)i*i-(ll)i*dp[i]); } cout<<sum<<endl; } return 0;}
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- 浙大校赛 ZOJ 3956Course Selection System (01背包)
- 浙大17年校赛(ZOJ 3956)Course Selection System[01背包]
- 2017 浙大校赛 Course Selection System(01背包)
- ZOJ 3956 Course Selection System 01背包
- Zoj 3956 Course Selection System【01背包】
- ZOJ 3956 Course Selection System 01背包
- ZOJ-3956 Course Selection System,01背包!
- ZOJ-3956 Course Selection System(01背包)
- zoj 3956-Course Selection System(背包)
- ZOJ 3956 Course Selection System(01背包)
- Zoj 3956 Course Selection System (01背包)
- ZOJ 3956 Course Selection System 01背包变形
- ZOJ 3956 Course Selection System (dp 01背包)
- ZOJ 3956 Course Selection System(01背包变形)
- ZOJ 3956 Course Selection System 【 思维 + 01背包 】
- 浙大校赛- Course Selection System
- JS封装类或对象的最佳方案
- 过滤器,拦截器区别
- 深度学习——sgd等优化方法比较
- 树形结构数据的提交
- 修改WAMPServer默认的网站路径地址的一种方式
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- Java web
- LCT学习总结
- git创建本地master,用于提交至其他master
- 记录一下自己在mini2440上面 使用uboot的曲折的经历
- @Controller和@RestController的区别?
- shape.gradient使用示例
- @RequestBody 只能与@RequestHeader同用 不能与@RequestParam (实现迭代函数部分方法只调用一次,之后传递下去)
- div中的table等居中