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. 【编程之外】还记得曾经给'大学导师'写过的报告嘛 --> 前方高能

    写在前面 本文不是讲技术的,也没什么代码可看 本文不是讲技术的,也没什么代码可看 本文不是讲技术的,也没什么代码可看 还记得我们曾经给我们大学''导师''写过的报告嘛? 大学他愿意在凌晨6点向你询问近 ...

  2. css3新属性的学习使用

    display 可选值:none隐藏元素: block显示为块级元素: inline显示为行级元素 inlineblock显示为内联块级元素,本身将是一个行级元素,但是拥有 块级元素的所有属性,比如宽 ...

  3. mvc一对多模型表单的快速构建

    功能需求描述 Q:在实际的开发中,经常会遇到一个模型中包含有多个条目的表单.如何将数据提交到后台? A: 以数组的形式提交到后台就Ok了(真的那么简单么,如果再嵌套一层呢?) A2:拆分多个模型,映射 ...

  4. java 面向对象 1

    目录 一.面向过程的思想和面向对象的思想 二.简单理解面向对象 三.面向对象的设计思想 四.对象和类的概念 五.如何抽象出一个类? 六.类(对象)之间的关系 七.Java与面向对象 八.为什么使用面向 ...

  5. Finally-操作返回值

    Finally中操作返回会出现一个问题?直接看代码 static int M1() { ; try { result = result + ; //======引发异常的代码========== , ...

  6. 深入理解计算机系统chapter6

    1. 2. 3. 存储器山

  7. 张高兴的 Windows 10 IoT 开发笔记:使用 Lightning 中的软件 PWM 驱动 RGB LED

    感觉又帮 Windows 10 IoT 开荒了,所以呢,正儿八经的写篇博客吧.其实大概半年前就想写的,那时候想做个基于 Windows 10 IoT 的小车,但树莓派原生不支持 PWM 啊.百度也搜不 ...

  8. Day3 Python基础学习——文件操作、函数

    一.文件操作 1.对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过文件句柄对文件进行操作 关闭文件 #打开文件,读写文件,关闭文件 http://www.cnblogs.com/linha ...

  9. URL不能过长,否则summit方法提交失败

    MVC5.0+EF6.0,和浏览器的版本有关系.IE最多1024KB. URL不能过长,否则summit方法提交失败.

  10. Asp.net MVC4高级编程学习笔记-视图学习第三课Razor页面布局20171010

    Razor页面布局 1)  在布局模板页中使用@RenderBody标记来渲染主要内容.比如很多web页面说头部和尾部相同,中间内容部分使用@RenderBody来显示不同的页面内容. 2)  在布局 ...