Happy Programming Contest zoj3703 dp
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 wowould 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 follows 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 same as possible. if there are always 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 shoshould 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) Question: there is a right to go to the competition. Brought a girl. Each question has a value that attracts girls. It gives you the total time, some questions, and each question gives you the time spent and the appeal value. Then, you can select A question A solution within the total time to maximize the attractiveness. If there are multiple situations, you can choose A solution with A large number of questions. If there are multiple situations, select less penalty. (Don't care if you can win)
(2) solution: the knapsack problem. This article focuses on the following comparison relationships. If you look at the first condition, it is the bare 01 backpack, but then process the remaining two conditions, that is, add some conditions in the status transfer: f [v] = max {f [v], f [v-c [I] + w [I]}. When the conditions are met, the status is transferred again. First, to meet the attractiveness of the situation, then consider the number of problems to solve, and finally consider the issue of penalty. Such a single backpack f [v] = max {f [v], f [v-c [I] + w [I]} becomes a multivariate condition.
# 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, & sumtime, & n); for (I = 0; I
= Time [I]; j --) {if (dp [j]
Fuck [j-time [I] + zs [j-time [I] + time [I]) // At least {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 ++) // find the largest {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, outlove, outjie, outsumtime);} return 0 ;}