ZOJ3703 Happy Programming Contest
来源:互联网 发布:淘宝店铺营销策划方案 编辑:程序博客网 时间:2024/04/29 21:25
In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Since the girl would prefer pink balloon rather than black balloon, each color is assigned a value to measure its attractiveness. Usually, the boy is good at programming while the girl is charming. The boy wishes to solve problems as many as possible. However, the girl cares more about the lovely balloons. Of course, the boy's primary goal is to make the girl happy rather than win a prize in the contest.
Suppose for each problem, the boy already knows how much time he needs to solve it. Please help him make a plan to solve these problems in strategic order so that he can maximize the total attractiveness value of balloons they get before the contest ends. Under this condition, he wants to solve problems as many as possible. If there are many ways to achieve this goal, he needs to minimize the total penalty time. The penalty time of a problem is equal to the submission time of the correct solution. We assume that the boy is so clever that he always submit the correct solution.
The first line of input is an integer N (N < 50) indicating the number of test cases. For each case, first there is a line containing 2 integers T (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line contains n integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containing n integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of the i-th problem. Time is measured in minutes.
For each case, output a single line containing 3 integers in this order: the total attractiveness value, the number of problems solved, the total penalty time. The 3 integers should be separated by a space.
2300 1010 10 10 10 10 10 10 10 10 101 2 3 4 5 6 7 8 9 10300 10301 301 301 301 301 301 301 301 301 3011000 1000 1000 1000 1000 1000 1000 1000 1000 1000
55 10 5500 0 0
按时间排序做背包即可
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>using namespace std;const int N=1e5+10;const int mod=1e9+7;int T,t,n,u[N],v[N],a[N];int dp[55][1055];int sl[55][1055];int fs[55][1055];bool cmp(int x,int y){ return u[x]<u[y]; }int main(){ for (scanf("%d",&T);T--;) { scanf("%d%d",&t,&n); for (int i=1;i<=n;i++) scanf("%d",&u[i]); for (int i=1;i<=n;i++) scanf("%d",&v[i]); for (int i=1;i<=n;i++) a[i]=i; sort(a+1,a+n+1,cmp); memset(dp,0,sizeof dp); memset(sl,0,sizeof sl); memset(fs,0,sizeof fs); for (int i=1;i<=n;i++) { int x=a[i]; for (int j=0;j<=t;j++) { dp[i][j]=dp[i-1][j]; sl[i][j]=sl[i-1][j]; fs[i][j]=fs[i-1][j]; } for (int j=u[x];j<=t;j++) { if (dp[i][j]<dp[i-1][j-u[x]]+v[x]) { dp[i][j]=dp[i-1][j-u[x]]+v[x]; sl[i][j]=sl[i-1][j-u[x]]+1; fs[i][j]=fs[i-1][j-u[x]]+j; } else if (dp[i][j]==dp[i-1][j-u[x]]+v[x]) { if (sl[i][j]<sl[i-1][j-u[x]]+1) { sl[i][j]=sl[i-1][j-u[x]]+1; fs[i][j]=fs[i-1][j-u[x]]+j; } else if (sl[i][j]==sl[i-1][j-u[x]]+1) { fs[i][j]=min(fs[i][j],fs[i-1][j-u[x]]+j); } } } } int x=0,y=0,z=0; for (int i=0;i<=t;i++) { if (dp[n][i]>x) x=dp[n][i],y=sl[n][i],z=fs[n][i]; else if (dp[n][i]==x&&sl[n][i]>y) y=sl[n][i],z=fs[n][i]; else if (dp[n][i]==x&&sl[n][i]==y) z=min(z,fs[n][i]); } printf("%d %d %d\n",x,y,z); } return 0;}
- ZOJ3703 Happy Programming Contest
- ZOJ3703 Happy Programming Contest
- ZOJ3703-Happy Programming Contest
- ZOJ3703 Happy Programming Contest
- Happy Programming Contest zoj3703 dp
- 01背包好题 ZOJ3703 Happy Programming Contest
- H - Happy Programming Contest
- ZOJ 3703 Happy Programming Contest
- ZOJ 3703 Happy Programming Contest
- ZOJ 3703 Happy Programming Contest
- ZOJ 3703 Happy Programming Contest
- ZOJ 3703 Happy Programming Contest(贪心+0/1背包)
- 北大校赛提前热身,Happy Programming Contest和Digging
- zoj 3703 Happy Programming Contest 不平常的01背包
- (又是一个奇葩题目)Happy Programming Contest
- Happy Programming Contest ZOJ+01背包问题+路径输出
- ZOJ 3703 Happy Programming Contest 0-1背包 DP
- ZOJ 3703 Happy Programming Contest(0-1背包)
- 蓝桥杯之包子凑数
- 2017最新java工程师面试笔试题集锦(一)
- 加油!
- WC2013糖果公园
- 二叉树的实现
- ZOJ3703 Happy Programming Contest
- fl2440——驱动学习-ADC驱动
- 初学自定义view(自定义属性)
- 树链剖分简述
- 案例------用户登录记住密码
- eclipse安装nodeclipse(nodejs集成开发环境)
- caffe上手:caffe训练一般过程--wanglei 写给自己
- 全排列问题
- Git版本控制器的使用教程(简单入门级)