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. MySQL基本语法(一):和SQL Server语法的差异小归纳

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  2. oracle sql*plus常用命令

    一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...

  3. 理解AngularJS中的依赖注入

    点击查看AngularJS系列目录 理解AngularJS中的依赖注入 AngularJS中的依赖注入非常的有用,它同时也是我们能够轻松对组件进行测试的关键所在.在本文中我们将会解释AngularJS ...

  4. AngularJS 1.3中的一次性数据绑定(one-time bindings)

    点击查看AngularJS系列目录 谈谈AngularJS 1.3中的一次性数据绑定(one-time bindings) 不久之前,AngularJS 1.3版本正式发布,其中添加了很多的性特性,同 ...

  5. C#操作SqlServer MySql Oracle通用帮助类Db_Helper_DG(默认支持数据库读写分离、查询结果实体映射ORM)

    [前言] 作为一款成熟的面向对象高级编程语言,C#在ADO.Net的支持上已然是做的很成熟,我们可以方便地调用ADO.Net操作各类关系型数据库,在使用了多年的Sql_Helper_DG后,由于项目需 ...

  6. 使用jquery的方法和技巧

    1.下载一个jquery.js的文件 2.引入jquery.js文件 <script type="text/javascript" src="__PUBLIC__/ ...

  7. TETELaser Cutting System 不连续吹起的问题

    TETELaser Cutting System 不连续吹起的问题    :配置 加工参数-->机器参数-->信号灯和激光器报警:黄灯索引==EX14   红灯索引==EX15 绿灯索引= ...

  8. Glide 这样用,更省内存!!!

    一.前言 Glide 是 Google 官方推荐的一款图片加载库,使用起来也非常的简单便利,Glide 它帮我们完成了很多很重要,但是却通用的功能,例如:图片的加载压缩.展示.加载图片的内存管理等等. ...

  9. qplot函数用法(转载)

    http://blog.csdn.net/u014801157/article/details/24372499 写的很全面 放在这里记录下

  10. 通过修改 LayoutInflater,全局替换字体!!!

    序 在 Android 下使用自定义字体已经是一个比较常见的需求了,最近也做了个比较深入的研究. 那么按照惯例我又要出个一篇有关 Android 修改字体相关的文章,但是写下来发现内容还挺多的,所以我 ...