Doing Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8945    Accepted Submission(s): 4193

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
 

题意:

有n种作业,每种作业有一个上交时间和写完这个作业花费的时间,每种作业超过上交时间几天完成就扣几分,问如何安排作业顺序才能扣分最少。

代码:

//只有15种作业,压缩一下状态,枚举状态然后枚举这个状态能做的每一种作业,
//若这个作业在这时做是否最优,进行dp.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int t,n,cost[],dead[];
char pro[][];
struct Lu{
int sco,tim,now,pre;
}L[<<];
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%s%d%d",pro[i],&dead[i],&cost[i]);
int N=<<n;
for(int i=;i<N;i++) L[i].sco=inf;
L[].sco=L[].tim=;
for(int i=;i<N;i++){
for(int j=n;j>=;j--){
if(i&(<<(n-j))){
int sta=i^(<<(n-j));
int p=L[sta].tim+cost[j]-dead[j];
if(p<) p=;
if(L[i].sco>L[sta].sco+p){
L[i].sco=L[sta].sco+p;
L[i].tim=L[sta].tim+cost[j];
L[i].now=j;
L[i].pre=sta;
}
}
}
}
printf("%d\n",L[N-].sco);
int p=N-,ans[],nu=;
while(p){
ans[++nu]=L[p].now;
p=L[p].pre;
}
for(int i=nu;i>=;i--)
printf("%s\n",pro[ans[i]]);
}
return ;
}

HDU 1074状压DP的更多相关文章

  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. Doing Homework(HDU 1074状压dp)

    题意:给你n个要做的作业,它们的名字.期限.可完成所需天数(必须连续)在规定期限不能完成要扣分(每天一分)求做作业顺序使扣分最少. 分析:作业数量较少,用状态压缩,做到第i种作业花费的天数dp[i]. ...

  3. hdu 1074 (状压dp)

    题意: 给出几个学科的作业.每个作业剩余的时间.完成每个学科作业的时间.如果在剩余时间内不能完成相应作业 就要扣分 延迟一天扣一分 求最小扣分 解析: 把这些作业进行全排列  求出最小扣分即可 但A( ...

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

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

  5. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  6. HDU 3001 状压DP

    有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路  成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...

  7. hdu 2809(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...

  8. hdu 2167(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167 思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为d ...

  9. Engineer Assignment HDU - 6006 状压dp

    http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...

随机推荐

  1. 【递归入门】组合+判断素数:dfs(递归)

    题目描述 已知 n 个整数b1,b2,…,bn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和. 例如当 n=4,k=3,4 个整数分别为 3,7,12, ...

  2. ElasticSearch 论坛搜索查询语句

    概述 研究论坛搜索如何综合时间和TF/IDF权重. 自定义权重计算的效率问题 数据结构 假设有一个论坛的搜索 字段包括: subject:标题 message:内容 dateline:发布时间 tag ...

  3. 6.hdfs的存储过程

    1.hdfs 怎么存储 切割存储 2. 为何每块是128m 与io读写速度有关,一般人的接受速度1s中,而磁盘的读写速度为100m/s,在读取文件时候需要硬盘寻找地址,一般读懂速度和寻找之间的比例是1 ...

  4. BZOJ 4176 Lucas的数论 莫比乌斯反演+杜教筛

    题意概述:求,n<=10^9,其中d(n)表示n的约数个数. 分析: 首先想要快速计算上面的柿子就要先把d(ij)表示出来,有个神奇的结论: 证明:当且仅当a,b没有相同的质因数的时候我们统计其 ...

  5. Java学习个人备忘录之数组工具类

    下面主要讲解一个针对数组操作的工具类. a.java -- 工具类文件 //按理来说要先编译本文件, 然后再编译主函数 class ArrayTool { /* 获取整型数组的最大值 */ publi ...

  6. 20162328蔡文琛week09

    学号 2016-2017-2 <程序设计与数据结构>第X周学习总结 教材学习内容总结 数据库是为了其他程序提供数据的应用软件. 关系书就哭通过唯一的标识符在不同表的记录见建立了关系. JD ...

  7. js 拼接字符串时,本来想要’#1′ ,返回的却是’#01′

    今天在操作一个元素时,id值是拼接的. var index = $(this).attr(‘index’);    //0var id = ‘#’ + (index+1);    //#01$(id) ...

  8. Jenkins系列-Jenkins介绍与部署

    Jenkins是什么? Jenkins是一个功能强大的应用程序,允许持续集成和持续交付项目,无论用的是什么平台.这是一个免费的源代码,可以处理任何类型的构建或持续集成.集成Jenkins可以用于一些测 ...

  9. c++:error2019,无法解析的外部命令blabla~

    出现这个原因的问题汇总: 1,相应的附加库没有包含进去,注意附加库的目录是 / 2,函数没有与之对应的类,却在main中以某一类的对象调用了该方法. 其实,当错误中显示fun()成为无法解析的外部命令 ...

  10. MySQL错误解决10038

    [错误解决]本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止 标签: mysql计算机 2016-12-01 17:49 5508人阅读 评论(2) 收藏 举报   ...