Doing Homework HDU - 1074
InputThe 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.
OutputFor 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.
第一个DP状态压缩的题,看了好久。希望下次做的时候可以懂一点点吧。
// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#define INF 0x3f3f3f3f
#define mod 2016
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = (<<)+;
int n, m, T, len, cnt, num, ans, Max;
int dp[maxn], t[maxn], pre[maxn], d[], f[];
char str[][]; void output(int x) {
if( !x ) return ;
output(x-(<<pre[x]));
printf("%s\n", str[pre[x]]);
} void input() {
scanf("%d", &T);
while( T -- ) {
scanf("%d", &n);
for(int i=; i<n; i++) scanf("%s%d%d",str[i], &d[i], &f[i]);
int bit = << n;
for(int i=; i<=bit; i++) {
dp[i] = INF;
for(int j=n-; j>=; j--) {
int te = <<j;
if( !(i&te) ) continue;
int sc = t[i-te]+f[j]-d[j];
if( sc< ) sc = ;
if( dp[i]>dp[i-te]+sc) {
dp[i] = dp[i-te]+sc;
t[i] = t[i-te]+f[j];
pre[i] = j;
}
}
}
printf("%d\n", dp[bit-]);
output(bit-);
}
} int main() {
input();
return ;
}
感谢大神http://blog.csdn.net/xingyeyongheng/article/details/21742341
Doing Homework HDU - 1074的更多相关文章
- Doing Homework HDU - 1074 (状压dp)
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...
- D - Doing Homework HDU - 1074 (状压dp)
题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求 10 ...
- Doing Homework HDU - 1074 状态压缩
#include<iostream> #include<cstring> #include<cstdio> #include<string> #incl ...
- Day9 - G - Doing Homework HDU - 1074
有n个任务,每个任务有一个截止时间,超过截止时间一天,要扣一个分.求如何安排任务,使得扣的分数最少.Input有多组测试数据.第一行一个整数表示测试数据的组数第一行一个整数n(1<=n<= ...
- 【状态DP】 HDU 1074 Doing Homework
原题直通车:HDU 1074 Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...
- HDU 1074 Doing Homework (动态规划,位运算)
HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
- HDU 1074:Doing Homework(状压DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Problem Description Ignatius has just ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
随机推荐
- crm 理解
1:crm 就是一个 能够随时(通过labtop,mobile phone)掌握客户所有信息(过往的交易,)的工具. 通过足够的数据分析,能够更好的了解客户. 目的: a:使客户保留下来. b:赚取 ...
- 118A
#include <iostream> #include <cctype> #include <string> using namespace std; int m ...
- Django 框架 数据库操作
数据库与ORM 1 django默认支持sqlite,mysql, oracle,postgresql数据库. <1> sqlite django默认使用sqlite的数据库,默认 ...
- 【Scrum】-NO.40.EBook.1.Scrum.1.001-【敏捷软件开发:原则、模式与实践】- Scrum
1.0.0 Summary Tittle:[Scrum]-NO.40.EBook.1.Scrum.1.001-[敏捷软件开发:原则.模式与实践]- Scrum Style:DesignPattern ...
- 第二弹:超全Python学习资源整理(进阶系列)
造一个草原要一株三叶草加一只蜜蜂.一株三叶草,一只蜂,再加一个梦.要是蜜蜂少,光靠梦也行. - 狄金森 "成为编程大牛要一门好语言加一点点天分.一门好语言,一点点天分,再加一份坚持.要是天分 ...
- Java编写email实现内容换行
用java编写的发送邮件要使用<br>来实现换行,而不能使用\n,或者\r\n // 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发 ...
- 启用了不安全的HTTP方法【转】
安全风险: 可能会在Web 服务器上上载.修改或删除Web 页面.脚本和文件. 可能原因: Web 服务器或应用程序服务器是以不安全的方式配置的. 修订建议: 如果 ...
- equals和==的区别小结
==: == 比较的是变量(栈)内存中存放的对象的(堆)内存地址,用来判断两个对象的地址是否相同,即是否是指相同一个对象.比较的是真正意义上的指针操作. 1.比较的是操作符两端的操作数是否是同一个对象 ...
- 正则表达式中\b和\s有什么区别
字符串:abcsdsadas abc asdsadasdabcasdsa使用\sabc\s和\babc\b都能匹配中间的abc,这种方法不是重复了么,/s是匹配空格回车等得,/b网上教程说得不清楚什么 ...
- Docker日志
搜索Redis镜像 docker search redis ***************************** 拉取Redis镜像 docker pull redis ************ ...