浙大校赛- Course Selection System
来源:互联网 发布:三菱plcfx3u编程实例 编辑:程序博客网 时间:2024/05/19 01:13
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
2310 15 12 1021 102 10
Sample Output
1910
这道题题目大意很简单,这道题就是给了一个公式,求最大值:
#include <iostream>#include <algorithm>#include <queue>#include <cstdio>#include <cstdlib>#include <vector>#include <cstring>#include <string>using namespace std;typedef long long ll;struct{ int h; int c;} cur[505];ll hmin[50005];ll hmax[50005];int main(){ int t; scanf("%d",&t); while(t--) { memset(hmax,0,sizeof(hmax)); int n,sum; sum=0; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d%d",&cur[i].h,&cur[i].c); sum+=cur[i].c; } // cout<<sum<<endl; hmin[sum]=cur[n].h; hmax[sum]=cur[n].h; hmax[0]=hmin[0]=0; /* for(int i=1; i<=n; i++) { for(int j=sum; j>=1; j--) { hmin[j]=min(hmin[j],hmin[j-cur[i].c]+cur[i].h); } }*/ for(int i=1; i<=n; i++) { for(int j=sum; j>=1; j--) { if(j-cur[i].c>=0) hmax[j]=max(hmax[j],hmax[j-cur[i].c]+cur[i].h); } } /* for(int i=1;i<=sum;i++){ cout<<hmax[i]<<" "; }*/ ll res=0; for(int i=1;i<=sum;i++){ ll ans=hmax[i]*hmax[i]-hmax[i]*i-i*i; res=max(res,ans); } printf("%lld\n",res); } return 0;}
0 0
- 浙大校赛- Course Selection System
- 2017 浙大校赛 Course Selection System(01背包)
- 浙大校赛 ZOJ 3956Course Selection System (01背包)
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- 浙大17年校赛(ZOJ 3956)Course Selection System[01背包]
- Course Selection System ZOJ
- Course Selection System ***
- ZOJ 3956 Course Selection System
- Course Selection System 01背包
- ZOJ 3956 Course Selection System
- zoj3956 Course Selection System (背包)
- zoj 3956 Course Selection System
- 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)
- 今天挺晚的,十点多了。
- C++第五次上机实验——数组分离
- VR系列——Oculus Rift 开发者指南:一、LibOVR集成
- ionic-下拉刷新载入数据
- python读取网页
- 浙大校赛- Course Selection System
- Struts2(二)——配置文件struts2.xml的编写
- 为什么数据库表的int类型字段映射到实体类中要使用Integer类型,而不是int类型?
- 求逆元的两种方法
- 线程池调整真的很重要
- Spring MVC和AJAX异步交互实例
- Android Material Design 材料设计
- 数据结构之环形队列应用(2)
- C语言程序设计(13)