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.

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的更多相关文章

  1. 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 ...

  2. D - Doing Homework HDU - 1074 (状压dp)

    题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求  10 ...

  3. Doing Homework HDU - 1074 状态压缩

    #include<iostream> #include<cstring> #include<cstdio> #include<string> #incl ...

  4. Day9 - G - Doing Homework HDU - 1074

    有n个任务,每个任务有一个截止时间,超过截止时间一天,要扣一个分.求如何安排任务,使得扣的分数最少.Input有多组测试数据.第一行一个整数表示测试数据的组数第一行一个整数n(1<=n<= ...

  5. 【状态DP】 HDU 1074 Doing Homework

    原题直通车:HDU  1074  Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...

  6. HDU 1074 Doing Homework (动态规划,位运算)

    HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...

  7. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  8. HDU 1074:Doing Homework(状压DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Problem Description Ignatius has just ...

  9. HDU 1074 Doing Homework(状压DP)

    第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...

随机推荐

  1. vue【指令】

    <div class="m-conbox"> <div v-text="html"></div> <div>{{ ...

  2. GENIA语料库学习【转载】

    来自论文:GENIA corpus—a semantically annotated corpus for bio-textmining  2003 1.介绍 GENIA corpus, a sema ...

  3. 2018-2019-1 20189221《Linux内核原理与分析》第三周作业

    2018-2019-1 20189221<Linux内核原理与分析>第三周作业 实验二 完成一个简单的时间片轮转多道程序内核代码 实验过程 在实验楼中编译内核 编写mymain.c函数和m ...

  4. spring注解注入的学习

    spring在开发中起到管理bean的作用,不管是web应用还是应用软件开发.注入有多种方式,其中注解注入最为受欢迎.(java api 在1.6版本以上才引入关键的注解类如:@Resource) 配 ...

  5. 通过官方API结合源码,如何分析程序流程

    通过官方API结合源码,如何分析程序流程通过官方API找到我们关注的API的某个方法,然后把整个流程执行起来,然后在idea中,把我们关注的方法打上断点,然后通过Step Out,从内向外一层一层分析 ...

  6. 带上RESTful的金手铐,你累吗?

    1. 首先RESTful是一套规范,不是框架,它是来约束你的.也不关心生产效率的提高.就好像使用汇编开发应用,性能是快了,但是生产效率很低.RESTful它需要你在路由上定义很多规则来解释的URL,假 ...

  7. Photoshop去图片水印——适用复杂图片上有水印

    该方法适合复杂图片上有水印的,不过这个只适合水印只是文字而没有背景的那种.不是所有的水印图片都适合处理.下面是处理前后的对照   工具/原料   photoshop8.0 方法/步骤   1 打开需要 ...

  8. sqli-labs(十二)(and和or的过滤)

    第二十五关: 这关是过滤了and 和or 输入?id=1' or '1'='1 发现or被过滤了,将or换成and也一样. 输入?id=1' oorr '1'='1 这样就可以了,将一个or置空后,o ...

  9. 1.display:flex布局笔记

    /*display:flex布局方式主要运用于垂直居中的效果*/ 一.Flex译为Flexible Box(弹性盒子),任何一个容器都可以指定为Flex布局 注:设置为Flex布局之后,子元素的flo ...

  10. PHP数据库环境配置

    wamp环境   w是windows系统       a是Apache(服务器管理软件)      m是MySQL(数据库)    p是PHP wamp正常情况下是绿色的可以正常使用 黄色和红色不能使 ...