hdu1074(状压DP)
2014-11-27 16:20
211 查看
这题本来很简单,代码被我写搓了,字母翘错了一个一直不出结果。
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<map> #include<stack> using namespace std; typedef long long lld; #define oo 0x3f3f3f3f #define maxn 1<<16 int mark[maxn]; struct DP { int min_re_s; int time; int pre; int key; }dp[maxn]; struct Class { int dealine; int time; char name[102]; }a[16]; void OutPutAns(int st) { if (dp[st].pre == -1) return; OutPutAns(dp[st].pre); printf("%s\n", a[dp[st].key].name); } int main() { int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%s %d %d", a[i].name, &a[i].dealine, &a[i].time); for (int i = 0; i <= 1 << n; i++) dp[i].min_re_s = oo; dp[0].min_re_s = 0; dp[0].time = 0; dp[0].pre = -1; dp[0].key = 0; mark[0] = 1; int allst = (1 << n) - 1; for (int i = 0; i <= allst; i++) { for (int j = 0; j < n; j++) { if (i&(1 << j)) continue; int st = i | (1 << j); int time = dp[i].time + a[j].time; int min_re_s = time - a[j].dealine; if (min_re_s < 0) min_re_s = 0; if (min_re_s + dp[i].min_re_s < dp[st].min_re_s) { dp[st].min_re_s = min_re_s + dp[i].min_re_s; dp[st].pre = i; dp[st].time = time; dp[st].key = j; } } } printf("%d\n", dp[allst].min_re_s); OutPutAns(allst); } return 0; }
相关文章推荐
- HDU 1074 状压DP
- hdu 1074 Doing Homework(状压DP)
- hdu_1074_Doing Homework(状压DP)
- hdu 1074 Doing Homework 状压dp
- hdu 1074 Doing Homework (状压dp)
- HDU 1074 Doing Homework (状压dp)
- hdu_1074_Doing Homework(状压DP)
- hdu1074 Doing Homework(状压dp)
- HDU 1074 Doing Homework(状压DP)
- HDU 1074 Doing Homework(状压DP)
- hdu 1074 状压dp
- hdu-1074(状压dp)
- HDU 1074 Doing Homework(状压DP)
- hdu1074 状压dp
- HDU 1074-Doing Homework(状压DP)
- hdu 1074 Doing Homework 状压dp
- HDU 1074 Doing Homework(状压dp)
- HDU 1074 Doing Homework(状压dp)
- HDU 1074 Doing Homework(状压DP)
- Hdu 1074 Doing Homework 状压dp