Doing Homework

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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.
         
/*
题意:给你n门功课,和对应的最后完成的日期,做完这门功课需要的时间,每门功课如果延迟的上交的话,每迟一天,就会扣一分,问怎么样安排
做功课的顺序才能是的减的分数最少。 初步思路:状压DP,最多15门功课,状态最多也就是2^15,设dp[i]为i状态的时候最少扣的分数状态转移方程为: dp[i]表示的是i状态扣得最少的分数,算出”加上!!!“第k这节课后所用的总时间time,time-第k节课期限,就是加上第k节课所需要的
扣的分数,然后下面的的状态转移方程就明白了 dp[i|(1<<k)]=max(dp[i|(1<<k)] ,dp[i]+time) 剩下的就是记录路径了,这个很简单就是用path数组记录一下状态转移的过程,在状态转移的过程中增加的课程就是咱们想要的到的结果 错误:眼瞎,path数组开小了,没看出来
*/
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
struct node{
char name[];
int end_time;
int use_time;
}course[];
int dp[(<<)];
int path[(<<)];//用来记录路径,path[i]=j,表示i状态是由j状态转移过来的
int t,n;
void init(){
memset(dp,INF,sizeof dp);
memset(path,-,sizeof path);
}
void print(int k){
if(k==) return ;//直到尽头,就是没有前一个状态了 for(int i=;i<n;i++){
//条件:k状态有这一位,并且去除这一位之后 是 转移到 k 的状态
if(( k&(<<i) )!= && path[k] == ( k-(<<i) ) ){//说明 k 状态和 k|(1<<i) 状态存在转移的关系
// cout<<k<<" "<<( k^i )<<endl;
print( path[k] ) ;
printf("%s\n",course[i].name);
break;
}
}
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d\n",&t);
while(t--){
init();
scanf("%d\n",&n);
for(int i=;i<n;i++){
scanf("%s %d %d\n",course[i].name,&course[i].end_time,&course[i].use_time);
// cout<<course[i].name<<" "<<course[i].end_time<<" "<<course[i].use_time<<endl;
}//处理输入 // for(int i=0;i<n;i++){
// cout<<course[i].name<<" "<<course[i].end_time<<" "<<course[i].use_time<<endl;
// } int tol=(<<n);//最多的状态为tol-1;
// cout<<tol<<endl;
dp[]=;//重要的初始化,什么课也不选的话就是不用扣分
for(int i=;i<tol;i++){//枚举状态
for(int j=n-;j>=;j--){//枚举没门功课加还是不加
if(( i&(<<j) )==){//如果这门功课还没选的话
int time=;//记录使用的时间
for(int k=;k<n;k++){//计算时间
if(( i&(<<k) )){//i状态下如果第k门功课选了就记录下他的时间
time+=course[k].use_time;
}
}
time+=course[j].use_time;
time=time-course[j].end_time;
if(time<) time=;//因为不可能出现扣出来负数的情况
// cout<<time<<endl;
if(dp[i|(<<j)]>dp[i]+time){
dp[i|(<<j)]=dp[i]+time;//更新加上第j门功课的状态
//记录一下
path[i|(<<j)]=i;
// cout<<(i|(1<<j))<<" "<<i<<endl;
}
}
}
}
printf("%d\n",dp[tol-]);
// cout<<"**********"<<endl;
print(tol-);
// cout<<"**********"<<endl;
}
return ;
}

Doing Homework的更多相关文章

  1. bzoj 4320: ShangHai2006 Homework

    4320: ShangHai2006 Homework Time Limit: 10 Sec Memory Limit: 128 MB Description 1:在人物集合 S 中加入一个新的程序员 ...

  2. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  3. hdu-1789-Doing Homework again

    /* Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  4. HDU 1789 Doing Homework again (贪心)

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

  5. Doing Homework 状态压缩DP

    Doing Homework 题目抽象:给出n个task的name,deadline,need.  每个任务的罚时penalty=finish-deadline;   task不可以同时做.问按怎样的 ...

  6. 机器学习 —— 概率图模型(Homework: Exact Inference)

    在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...

  7. hdoj 1789 Doing Homework again

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. homework做了些什么?

    第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...

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

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

  10. hdu1074 Doing Homework(状态压缩DP Y=Y)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. 逆向实战干货,快速定位自动捡阳光Call,或者标志

    逆向实战干货,快速定位自动捡阳光Call,或者标志 注意: 关于CE和OD的使用,这里不再多说,快速定位,默认大家已经有了CE基础,或者OD基础. 第一种方法,找Call 第一步,打开CE,搜索阳光值 ...

  2. 我的第一个python web开发框架(1)——前言

    由于之前经验不是很丰富,写的C#系统太过复杂,所以一直想重写,但学的越多越觉得自己懂的越少,越觉的底气不足.所以一直不敢动手,在内心深处对自己讲,要静下心来认真学习,继续沉淀沉淀.这两年多以来找各种机 ...

  3. String的replace和replaceAll

    replace(CharSequence target, CharSequence replacement) 这里CharSequence是一个接口 实现类包括CharBuffer, Segement ...

  4. 【转】css清除浮动float的三种方法总结,为什么清浮动?浮动会有那些影响?

    摘要: css清除浮动float的三种方法总结,为什么清浮动?浮动会有那些影响?     一.抛一块问题砖(display: block)先看现象: 分析HTML代码结构: <div class ...

  5. Java并发/多线程系列——初识篇

    回到过去,电脑有一个CPU,一次只能执行一个程序.后来多任务处理意味着计算机可以同时执行多个程序(AKA任务或进程).这不是真的"同时".单个CPU在程序之间共享.操作系统将在运行 ...

  6. Eddy's爱好 hdu2204

    Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. java 连接数据库测试类

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...

  8. Python实战之IO多路复用select实例

    Select方法: 句柄列表11, 句柄列表22, 句柄列表33 = select.select(句柄序列1, 句柄序列2, 句柄序列3, 超时时间)   参数: 可接受四个参数(前三个必须) 返回值 ...

  9. 纯CSS3实现轮播图

    前言 纯css3实现的轮播图效果,和JavaScript控制的相比,简单高效了很多,但是功能也更加单一,只有轮播不能手动切换. 用什么实现的呢?页面布局 + animation动画 HTML部分 &l ...

  10. SVN版本控制图标经常延时显示或未显示问题解决方法

    项目中,使用svn经常遇到,文件或文件夹图标延时显示或未显示的问题,终于找到办法解决 客户端:TortoiseSVN