ZOJ 3703 Happy Programming Contest(0

?problemCode=3703

Happy Programming ContestTime Limit: 2 Seconds Memory Limit: 65536 KB

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.

Input

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 integersT (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line containsn integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containingn integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of thei-th problem. Time is measured in minutes.

Output

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.

Sample Input2300 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 1000Sample Output55 10 5500 0 0

思路:0-1背包

<span style="font-size:18px;">#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;const int maxn=1010;int value[maxn],a[maxn],fv[maxn];int vis[55][maxn];int order[55];int main(){int N,length,n;cin>>N;while(N–){int time=0,sumtime=0,numbers=0;memset(vis,0,sizeof(vis));memset(fv,0,sizeof(fv));cin>>length>>n;for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)cin>>value[i];for(int i=1;i<=n;i++){for(int j=length;j>=a[i];j–){if(fv[j]<fv[j-a[i]]+value[i]){fv[j]=fv[j-a[i]]+value[i];vis[i][j]=1;}}}int cnt=0;int i=n;int j=length;for(;i>0;i–){if(vis[i][j]==1){order[cnt++]=a[i];j -= a[i];}}sort(order,order+cnt);for(int i=0;i<cnt;i++){time +=order[i];sumtime +=time;}cout<<fv[length]<< " " << cnt << " " << sumtime << endl;}return 0;}</span>

版权声明:本文为博主原创文章,未经博主允许不得转载。

,一路走来,我们无法猜测将是迎接什么样的风景,

ZOJ 3703 Happy Programming Contest(0

相关文章:

你感兴趣的文章:

标签云: