设为首页 加入收藏

TOP

Happy Programming Contest zoj3703 dp
2015-11-21 00:56:11 】 浏览:3063
Tags:Happy Programming Contest zoj3703

Description
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
2
300 10
10 10 10 10 10 10 10 10 10 10
1 2 3 4 5 6 7 8 9 10
300 10
301 301 301 301 301 301 301 301 301 301
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output
55 10 550
0 0 0

(1)题意:有个对要去比赛。带了个女孩。每个题都有吸引女孩的值。给你总时间,一些题,每个题给你所花时间,吸引力值。然后问你在总时间内,选取一种A题方案,使获得的吸引力值最大,如果有多种情况,则选择出题数较多的,如果也有多种情况,选择罚时较少的。(不在乎是否能赢)
(2)解法:背包问题。本题重点就是后面的几种比较关系;如果单看第一个条件,就是裸的01背包,但是再处理剩下的2个条件,也就是在状态转移中加入一些条件:f[v]=max{f[v],f[v-c[i]]+w[i]}。使得条件满足的情况下再进行状态的转移。先满足吸引力的情况,再考虑解题数量,最后考虑罚时问题。这样单一的背包f[v]=max{f[v],f[v-c[i]]+w[i]}变为多元条件。

#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         #include
        
          using namespace std; int main() { int k; scanf(%d,&k); while(k--) { int sumtime,n; int time[55],like[55]; int dp[1005]={0}; int zs[1005]={0}; int jie[1005]={0}; int fuck[1005]={0}; int i,j; scanf(%d %d,&sumtime,&n); for(i=0;i
         
          =time[i];j--) { if(dp[j]
          
           fuck[j-time[i]]+zs[j-time[i]]+time[i])//最后满足罚时最少 { jie[j]=jie[j-time[i]]+1; zs[j]=zs[j-time[i]]+time[i]; fuck[j]=fuck[j-time[i]]+zs[j-time[i]]+time[i]; dp[j]=dp[j-time[i]]+like[i]; } } } } } int outlove=0,outjie=0,outsumtime=0; for(i=0;i<=sumtime;i++) //找出最大的 { if(dp[i]>outlove) { outlove=dp[i]; outjie=jie[i]; outsumtime=fuck[i]; } else if(dp[i]==outlove) { if(jie[i]>outjie) { outlove=dp[i]; outjie=jie[i]; outsumtime=fuck[i]; } else if(jie[i]==outjie) { if(fuck[i]>outsumtime) { outlove=dp[i]; outjie=jie[i]; outsumtime=fuck[i]; } } } } printf(%d %d %d ,outlove,outjie,outsumtime); } return 0; } 
          
         
        
       
      
     
    
   

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ZOJ 3575 Under Attack III 下一篇POJ 3411 Paid Roads(DFS)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目