Doing Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7070    Accepted Submission(s): 3104

Problem 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
枚举会TLE,状态压缩DP,copy大神的:http://blog.csdn.net/y990041769/article/details/39546633
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=;
const int INF=0x3fffffff;
struct Node{
char s[];
int time,cost;
Node()
{
memset(s,,sizeof(s));
}
}a[MAXN];
int n;
int dp[<<MAXN];
int pre[<<MAXN];
void OutPut(int status)
{
if(status==)
return ;
int t=;
for(int i=;i<n;i++)
if((status&(<<i))!=&&(pre[status]&(<<i))==)
{
t=i;
break;
}
OutPut(pre[status]);
printf("%s\n",a[t].s);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%s",a[i].s);
scanf("%d%d",&a[i].time,&a[i].cost);
}
for(int i=;i<(<<MAXN);i++)
dp[i]=INF;
memset(pre,,sizeof(pre));
dp[]=;
for(int st=;st<(<<n);st++)
{
int w=;
for(int i=;i<n;i++)
{
if(st&(<<i))
w+=a[i].cost;
} for(int i=;i<n;i++)
{
if((st&(<<i))==)
{
if(dp[st|(<<i)]>dp[st]+max(,w+a[i].cost-a[i].time))
{
dp[st|(<<i)]=dp[st]+max(,w+a[i].cost-a[i].time);
pre[st|(<<i)]=st;
}
}
}
}
printf("%d\n",dp[(<<n)-]);
OutPut((<<n)-);
} return ;
}

HDU1074(状态压缩DP)的更多相关文章

  1. hdu1074 状态压缩dp+记录方案

    题意:       给你一些作业,每个作业有自己的结束时间和花费时间,如果超过结束时间完成,一天扣一分,问你把n个作业完成最少的扣分,要求输出方案. 思路:       状态压缩dp,记录方案数的地方 ...

  2. HDU1074(KB12-D 状态压缩dp)

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

  3. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  4. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  5. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  6. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  7. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  8. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  9. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

随机推荐

  1. 安装惠普M1136打印机一直处于“新设备已连接”状态怎么办?

    百度的答案是从控制面板的添加打印机入手,我试了遇到找不到设备的问题. 其实问题的原因是在安装驱动时一直把打印机到电脑的USB插着.我的解决方案是: 1.点击M1130MFP_M1210MFP开始安装, ...

  2. linux基础(5)- nginx服务、nfs服务

    一.nginx服务 源码安装: yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -yls ...

  3. Intel® RAID Software User’s Guide

    Intel® RAID Software User’s Guide: •Intel ® Embedded Server RAID Technology 2 •Intel ® IT/IR RAID •I ...

  4. EC2的维护更新

     2014年9月28日 近期几天.我们收到了一些客户关于我们即将进行维护更新的问题.下面是AWS全球Blog网站对这个问题的说明,供客户參照. 我们已经開始通知那些受影响的客户,关于我们即将实施的 ...

  5. CASIO fx-991es Plus科学计算器使用技巧

    关于输出: 默认是按照自然书写格式显示的,计算结果是按照分数形式显示,如0.5x0.5,会显示=1/4.虽然很直观,但是在测量和估算上略有不便.此时用 SHIFT --> MODE (也就是se ...

  6. Android获取手机方向

    假设用户开启了设置里的屏幕旋转,Android中处理横竖屏切换,通常的做法是在AndroidManifest.xml中定义android:configChanges="orientation ...

  7. C# wince 实现软件忙鼠标状态改变

    eg: Cursor.Current = Cursors.WaitCursor; dosomething(); Cursor.Current = Cursors.Default; Cursor.Cur ...

  8. jQuery param()作用与使用方法

    $.param()方法是serialize()方法的核心,用来对一个数组或对象按照key/value进行序列化. $.param(obj) 返回 :string: 说明:将jquery对象按照name ...

  9. spl处理文件(文件详细信息、文件遍历、查询指定行、写入CSV文件)

    <?php /** * 文件操作 */ //常用操作 $file = new SplFileInfo('D:/workspace/xlyy/spl/test.txt'); $file_info ...

  10. 诡异的json包含bom头

    今日项目碰到 需要调用php的一个接口  结果一直报返回的json字符串转对象  bom头报错 Exception in thread "main" com.fasterxml.j ...