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. GCD之异步同步体会

    前面的博文也有写到同步异步,可能是看他人的博文,自己没有实验,感觉理解不深,所以就敲了些代码比较一下串行.并行分别对应的同步.异步. 1.首先创建串行.并行线程队列 1 2 dispatch_queu ...

  2. PyTorch教程之Tensors

    Tensors类似于numpy的ndarrays,但是可以在GPU上使用来加速计算. 一.Tensors的构建 from __future__ import print_function import ...

  3. 第6章 Overlapped I/O, 在你身后变戏法 ---Win32 文件操作函数 -2

    Win32 之中有三个基本的函数用来执行 I/O,它们是:        i CreateFile()        i ReadFile()        i WriteFile()    没有另外 ...

  4. 第4章 同步控制 Synchronization ----同步机制的摘要

    同步机制摘要Critical Section Critical section(临界区)用来实现"排他性占有".适用范围是单一进程的各线程之间.它是:  一个局部性对象,不是一个核 ...

  5. C "right-left" 从左到右

    葵花宝典:http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html C混带代码大赛

  6. Racing Car Computer dp

    Racing Car Computer Input: Standard Input Output: Standard Output   The racing cars of today are equ ...

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

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

  8. Windows开启telnet服务 + 连接失败处理

    一.控制面板中安装Telnet相关组件 单击"开始"菜单,单击"控制面板"     在控制面板中单击打开"程序和功能"项目   在左侧的蓝色 ...

  9. Python之scrapy安装

    1.按照网上教程一步步实验,运行时报错: 'HtmlResponse' object has no attribute 'xpath' in scrapy 个人使用的是scrapy0.14.4,搜索得 ...

  10. easyUI tree点击文字展开节点

    easyUI默认展开树的时候,点击节点前边的黑色小三角 ,这样操作存在不人性化的地方,在实际使用中由于老旧电脑的存在和大龄使用者的眼花经常点不准:因此要实现点击节点名称展开的方式,其实就是在展开事件上 ...