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. AngularJS系列-翻译官网

    公司之前一直用的Web前台框架是Knockout,我们通常直接叫ko,有看过汤姆大叔的KO系列,也有在用,发现有时候用得不太顺手.本人是会WPF的,所以MVVM也是比较熟悉的,学ko也是很快就把汤姆大 ...

  2. String的replace和replaceAll

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

  3. taobao_api项目开坑,自主完成淘宝主要接口的开发-版本:卖家版(非淘宝api)

    项目名称:taobao_api 项目目的:独立实现各个淘宝操作的相关api,不依赖淘宝提供的api,而是自己实现接口 前期实现接口:已付款订单查询(自动更新), 订单发货 , 订单备注 应用场景:中小 ...

  4. [Tjoi2013]循环格

    [Tjoi2013]循环格 2014年3月18日1,7500 Description Input 第一行两个整数R,C.表示行和列,接下来R行,每行C个字符LRUD,表示左右上下. Output 一个 ...

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

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

  6. 使用Dapper进行参数化查询

    在使用Dapper操作Mysql数据库中我介绍了使用dapper进行CURD基本操作,但在示例代码中参数虽然也是通过@开头,但其实不是真正意义的参数化查询,而是拼接sql,这种方式不利于防止sql注入 ...

  7. Python 基础系列一:初识python(二)基本数据类型

    上节拾遗 1.编码转换过程,utf-8转换gbk 过程 经过解码(py27): x.decode('utf-8')-->unicode-->编码x.encode('gbk') ps:py3 ...

  8. MVC 中获取Json数据

    @{ ViewBag.Title = "json示例项目"; } @Scripts.Render("~/bundles/jquery") <h2>j ...

  9. 线性布局(LinearLayout)

    线性布局(LinearLayout) 备注 match_parent填充布局单元内尽可能多的空间 wrap_content完整显示控件内容 orientation有两个值,horizontal水平显示 ...

  10. 初识Hibernate之继承映射

         前面的两篇文章中,我们介绍了两张表之间的各种相互关联映射关系,但往往我们也会遇到两张表甚至多张表之间共有着多个相同的字段.例如: 如图,student表和teacher表共同具有id,nam ...