hdu1074---Doing Homework
来源:互联网 发布:软件开发数学 编辑:程序博客网 时间:2024/06/06 01:36
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 reduced 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 should output the smallest total reduced 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
2 3 Computer 3 3 English 20 1 Math 3 2 3 Computer 3 3 English 6 3 Math 6 3
Sample Output
2 Computer Math English 3 Computer English Math
Hint
In 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
简单的状态压缩dp
/************************************************************************* > File Name: dp6.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年02月12日 星期四 11时06分23秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;const int N = (1 << 15) + 100;int dp[N];char str[100];map <int, string> _hash;int n;struct node{ int deadline; int cost;}course[20];void dfs (int sta){ if (!sta) { return; } int next; for (int i = n - 1; i >= 0; --i) { if (!(sta & (1 << i))) { continue; } int tmp = sta ^ (1 << i); int cost = 0; for (int j = 0; j < n; ++j) { if (tmp & (1 << j)) { cost += course[j].cost; } } int use = course[i].cost + cost - course[i].deadline; if (use < 0) { use = 0; } if (dp[sta] == dp[tmp] + use) { next = i; break; } } dfs (sta ^ (1 << next)); printf("%s\n", _hash[next].c_str());}int main (){ int t; scanf("%d", &t); while (t--) { memset (dp, inf, sizeof(dp)); dp[0] = 0; _hash.clear(); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%s%d%d", str, &course[i].deadline, &course[i].cost); _hash[i] = str; } for (int i = 1; i < (1 << n); ++i) { for (int j = 0; j < n; ++j) { if ((i & (1 << j)) == 0) { continue; } int tmp = (i ^ (1 << j)); int x = 0; int cost = 0; for (int k = 0; k < n; ++k) { if (tmp & (1 << k)) { cost += course[k].cost; ++x; } } int use = cost + course[j].cost - course[j].deadline; if (use < 0) { use = 0; } if (dp[i] >= dp[tmp] + use) { dp[i] = dp[tmp] + use; } } } printf("%d\n", dp[(1 << n) - 1]); dfs ((1 << n) - 1); } return 0;}
- HDU1074--Doing Homework
- HDU1074 Doing Homework
- HDU1074 Doing Homework
- hdu1074 doing homework
- hdu1074---Doing Homework
- Doing Homework hdu1074
- HDU1074-Doing Homework
- HDU1074 Doing Homework
- HDU1074-Doing Homework
- Doing Homework HDU1074 【dp】
- HDU1074 - Doing Homework(状压DP)
- hdu1074:doing homework(状压dp)
- [HDU1074] Doing homework 状压DP
- hdu1074 Doing Homework 【状压dp】
- hdu1074 Doing Homework(状态压缩dp)
- hdu1074 Doing Homework (状态压缩dp)
- HDU1074 Doing Homework 状态压缩DP
- HDU1074:Doing Homework(状态压缩DP)
- 秒杀多线程第十六篇 多线程十大经典案例之一 双线程读写队列数据
- SpriteKit游戏开发点滴(0)前言
- adb logcat命令详解
- 黑马程序员——ObjC基础—属性及封装
- android开发环境安装视频教程
- hdu1074---Doing Homework
- 我的OC升级之路(一)
- ibatis, mybatis和Hibernate的区别
- 有趣的Java 3
- poj3267 dp
- 黑马程序员>>>Java多线程
- C# 浅析值类型与引用类型的内存分配
- Source Insight 常用设置和快捷键大全
- 键盘事件对应的数值