题意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一天则扣掉一单位学分, 要你求出完成所有作业而被扣最小的学分, 并将完成作业的顺序输出.

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<limits.h>
 4 #include<stdlib.h>
 5 #include<string.h>
 6 #include<cstring>
 7 #include<iomanip>
 8 #include<stdio.h>
 9 #include<bitset>
10 #include<cctype>
11 #include<math.h>
12 #include<string>
13 #include<time.h>
14 #include<vector>
15 #include<cmath>
16 #include<queue>
17 #include<stack>
18 #include<list>
19 #include<map>
20 #include<set>
21 
22 #define LL long long
23 
24 using namespace std;
25 const LL mod = 1000000007;
26 const double PI = acos(-1.0);
27 const int INF = 99999999;
28 const int M = 1005;
29 
30 struct node{
31     string name;
32     int time;
33     int date;
34 }a[16];
35 
36 struct DP{
37     int time;
38     int last;
39     int pos;
40     int score;
41 }dp[1 << 15 + 10];
42 
43 int main()
44 {
45     int t;
46     int n;
47     cin >> t;
48     while( t-- ){
49         cin >> n;
50         for(int i = 0; i < n; ++i)
51             cin >> a[i].name >> a[i].date >> a[i].time;
52         int bit = 1 << n;
53         int temp, past, redu;
54         for(int i = 1; i < bit; ++i){
55             dp[i].score = INF;
56             for(int j = n - 1; j >= 0; --j){
57                 temp = 1 << j;
58                 if(!(i & temp)) continue;
59                 past = i - temp;
60                 redu = dp[past].time + a[j].time - a[j].date;
61                 redu = max(redu,0);
62                 if(redu + dp[past].score < dp[i].score){
63                     dp[i].score = redu + dp[past].score;
64                     dp[i].pos = j;
65                     dp[i].last = past;
66                     dp[i].time = dp[past].time + a[j].time;
67                 }
68             }
69         }
70         stack<int> st;
71         redu = bit - 1;
72         while(redu)
73         {
74             st.push(dp[redu].pos);
75             redu = dp[redu].last;
76         }
77         cout << dp[bit - 1].score << endl;
78         while(!st.empty())
79         {
80             int top = st.top();
81             cout << a[top].name << endl;
82             st.pop();
83         }
84     }
85     return 0;
86 }
View Code

 

posted on 2015-03-24 21:11  Unico  阅读(137)  评论(0)    收藏  举报