ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品。。。。。每个背包的价值+0.01
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 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.
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 Input
Sample Output
55 10 550
0 0 0
Author: HUANG, Qiao
Contest: The 13th Zhejiang University Programming Contest
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 7 using namespace std; 8 9 struct timu 10 { 11 int w; 12 double v; 13 }TM[110]; 14 15 double bag[1100]; 16 int G[110][1100],V,N,t; 17 18 bool cmp(timu a,timu b) 19 { 20 return a.w<b.w; 21 } 22 23 int main() 24 { 25 cin>>t; 26 while(t--) 27 { 28 memset(bag,0,sizeof(bag)); 29 memset(G,0,sizeof(G)); 30 31 cin>>V>>N; 32 for(int i=1;i<=N;i++) cin>>TM[i].w; 33 for(int i=1;i<=N;i++) cin>>TM[i].v,TM[i].v+=0.01; 34 sort(TM+1,TM+1+N,cmp); 35 for(int i=1;i<=N;i++) 36 { 37 for(int j=V;j>=TM[i].w;j--) 38 { 39 if(bag[j]<=bag[j-TM[i].w]+TM[i].v) 40 { 41 G[i][j]=1; 42 bag[j]=bag[j-TM[i].w]+TM[i].v; 43 } 44 } 45 } 46 vector<int> vv; 47 int valu=V; 48 for(int i=N;i>=1;i--) 49 { 50 if(G[i][valu]) 51 { 52 valu-=TM[i].w; 53 vv.push_back(TM[i].w); 54 } 55 } 56 int nth=vv.size(); 57 int arr[110],time=0,tmp=0; 58 for(int i=0;i<nth;i++) arr[i]=vv[i]; 59 sort(arr,arr+nth); 60 for(int i=0;i<nth;i++) 61 { 62 tmp+=arr[i]; 63 time+=tmp; 64 } 65 cout<<(int)bag[V]<<" "<<nth<<" "<<time<<endl; 66 } 67 68 return 0; 69 }