HDU 1074 Doing Homework (pressure dp)
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 6299 Accepted Submission (s): 2708
Problem Description Ignatius has just come back school from the 30th ACM/ICPC. now he has a lot of homework to do. every teacher gives him a deadline of handing in the homework. if Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test, 1 day for 1 point. and as you know, doing homework always takes a long time. so Ignatius wants you to help him to arrange the order of doing homework to minimize the specified CED score.
Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case start with a positive integer N (1 <= N <= 15) which indicate the number of homework. then N lines follow. each line contains a string S (the subject's name, each string will at most has 100 characters) and two integers D (the deadline of the subject ), C (how many days will it take Ignatius to finish this subject's homework ).
Note: All the subject names are given in the alphabet increasing order. So you may process the problem much easier.
Output For each test case, you shocould output the smallest total CED score, then give out the order of the subjects, one subject in a line. if there are more than one orders, you should output the alphabet smallest one.
Sample Input
23Computer 3 3English 20 1Math 3 23Computer 3 3English 6 3Math 6 3
Sample Output
2ComputerMathEnglish3ComputerEnglishMathHintIn the second test case, both Computer->English->Math and Computer->Math->English leads to reduce 3 points, but the word English appears earlier than the word Math, so we choose the first order. That is so-called alphabet order.
Author Ignatius. L
/* After reading the question, I think the idea is roughly the same as that of the guest; both a and B can go to c. Although a and c are expensive, a may be short, because this time has an impact on the future, may a be defeated in the future? I feel that this is not easy to handle, but Baidu cannot find a solution. I finally figured it out. Since the status is the same, the time spent is the same, so I suddenly lost my doubts. */# include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define bug printf (hihi) # define eps 1e-8typedef _ int64 ll; using namespace std; # define INF 0x3f3f3f # define N 16 struct stud {int pre, time; // the point at which the current status comes from, the current status time, int score; // current score} dp [1 <16]; struct ha {string name; int d, len;} home [N]; int n; void show (int st) {if (st = 0) return; show (st ^ (1 <
Home [j]. d) score = time-home [j]. d; score + = dp [I]. score; if (dp [to]. score> score) {dp [to]. score = score; dp [to]. pre = j; dp [to]. time = time; // printf (% d: % d, to, to ^ (1 <
> Home [I]. name> home [I]. d> home [I]. len; // lexicographic input without sorting} DP ();} return 0 ;}