连接:http://acm.hdu.edu.cn/showproblem.php?pid=1074
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3973 Accepted Submission(s): 1581
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.
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.
#include <cstdio> #include <iostream> #include <cstring> #include <string> using namespace std ; #define M 1<<16 int n ; bool mask[M] ; struct node{ string name ; int need_time ; int limit_time ; }work[17] ; struct state{ int use_time ; int los_time ; int father ; int res ; }sta[M] , tmp ; void print( int t ){ if( t == 0 ) return ; print( sta[t].father ) ; cout<<work[ sta[t].res ].name<<endl ; } int main(){ int T ; scanf("%d" , &T ) ; while( T -- ){ scanf("%d" , &n ) ; for( int i = 0 ; i < n ; i ++ ){ cin>>work[i].name>>work[i].limit_time>>work[i].need_time ; } memset( sta , 0 , sizeof( sta ) ) ; memset( mask , false , sizeof( mask ) ) ; int m = 1<<n ; for( int i = 0 ; i < m ; i ++ ){ for( int j = 0 ; j < n ; j ++ ) if( ( i & ( 1<<j ) ) == 0 ) { int new_i = i | ( 1<<j ) ; tmp.use_time = sta[i].use_time + work[j].need_time ; tmp.los_time = sta[i].los_time + ( ( tmp.use_time > work[j].limit_time ) ? tmp.use_time - work[j].limit_time : 0 ) ; if( mask[new_i] == false || tmp.los_time < sta[new_i].los_time ){ mask[new_i] = true ; sta[new_i] = tmp ; sta[new_i].father = i ; sta[new_i].res = j ; } } } printf("%d\n" , sta[m-1].los_time ) ; print( m-1 ) ; } return 0 ; }
相关推荐
【标题】"HDU DP动态规划"涉及到的是在算法领域中的动态规划(Dynamic Programming,简称DP)技术,这是解决复杂问题的一种高效方法,尤其适用于有重叠子问题和最优子结构的问题。动态规划通常用于优化多阶段决策...
hdu 3341(ac自动机+状态压缩) 题意:容易理解... 思路:首先一开始容易想到要用到dp,开设一个dp[41][41][41][41][501]的数组来解决,但是明显内存已经超出范围了,于是就想如何减少内存呢?只要知道A、T、C、G其中...
动态规划(dynamic programming)是运筹学的一个分支,是求解决策过程(decision process)最优化的数学方法。20世纪50年代初美国数学家R.E.Bellman等人在研究多阶段决策过程(multistep decision process)的优化问题时,...
HDU上DP大集合,里面包括题,题解,代码,对DP入门者很实用,对DP老手也是有很大的提高
DP(Dynamic Programming,动态规划)是一种非常重要的算法思想,在 ACM HDU 题目分类中,DP 问题占据了很大的比例。例如,1003 DP 经典问题,最大连续子段和;1024 经典 DP,最大 M 子段和;1025 经典 DP,最长递增...
标题中的“DP.rar”表明这是一个关于动态规划的资料压缩包,而“DP_hdu”暗示了这些题目可能来自杭州电子科技大学(HDU)的在线编程平台。动态规划通常用于解决那些可以通过子问题的最优解来构建原问题最优解的问题...
HDU(杭州电子科技大学在线评测系统)是一个深受程序员喜爱的在线编程练习平台,它提供了丰富的算法题目供用户挑战,帮助他们提升编程技能和算法理解能力。"hdu.rar_hdu"这个压缩包文件很可能是某位程序员整理的他在...
【标题】"HDU_2010.rar"是一个压缩包文件,其中包含了与"HDU 2010"相关的资源,特别是针对"HDU ACM20"比赛的编程题目。"hdu 2010"和"hdu 20"可能是该比赛的不同简称或分类,而"hdu acm20"可能指的是该赛事的第20届...
【标题】"HDU题目java实现"所涉及的知识点主要集中在使用Java编程语言解决杭州电子科技大学(HDU)在线评测系统中的算法问题。HDU是一个知名的在线编程竞赛平台,它提供了大量的算法题目供参赛者练习和提交解决方案...
- **状态转移方程**:`dp[i] = max(dp[j] + 1)`,其中`j 并且`a[j] [i]`,即当前元素`a[i]`能作为递增子序列的末尾时,其最长递增子序列的长度为之前以`a[j]`结尾的最长递增子序列长度加1。 - **初始化**:对于每个...
hdu 1005.比较简单的一道题,有兴趣的可以看看。
【标题】"hdu.rar_HDU 1089.cpp_OJ题求和_hdu_horsekw5_杭电obj" 提供的信息是关于一个压缩文件,其中包含了一个名为 "HDU 1089.cpp" 的源代码文件,这个文件是为了解决杭州电子科技大学(Hangzhou Dianzi ...
根据提供的信息,我们可以总结出以下关于“hdu动态规划算法集锦”的知识点: ### 动态规划基础概念 动态规划是一种解决多阶段决策问题的方法,它通过将原问题分解为互相重叠的子问题,利用子问题的解来构建原问题...
### hdu1250高精度加法 #### 背景介绍 在计算机科学与编程竞赛中,处理大整数运算(特别是加法、减法、乘法等)是常见的需求之一。当数字的位数超过了标准数据类型(如`int`、`long`等)所能表示的最大值时,就需要...
HDU1059的代码
hdu1001解题报告
在HDU OJ中,DP题目如1003、1024等,通常需要选手对状态进行定义,并找出状态转移方程,从而求得问题的最优解。这类题目考验的是选手对复杂问题的抽象能力和优化策略的运用。 ### 搜索 搜索算法是解决问题的一种...
hdu 1574 passed sorce
hdu2101AC代码
【ACM HDU】指的是在ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)中,参赛者在杭州电子科技大学(Hangzhou Dianzi University,简称HDU)的在线评测系统上完成并已解决的题目集合...