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. POJ2386 Lake Counting 【DFS】

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20782   Accepted: 10473 D ...

  2. Java太阳系小游戏分析和源代码

    Java太阳系小游戏分析和源代码 -20150809 近期看了面向对象的一些知识.然后跟着老师的解说做了一个太阳系各行星绕太阳转的小游戏,来练习巩固一下近期学的知识: 用到知识点:类的继承.方法的重载 ...

  3. Solaris磁盘配额

    磁盘配额:就跟汽车行驶速度一样.我们设定. 添加rq标志,使其支持配额功能. 命令:quota ,打开就是quotaon 对ZFS文件系统进行设置配额: 当设置quota=none 则可以取消配额设置 ...

  4. solaris用户与文件权限管理

    此文章已于 20:45:28 2015/3/22 重新发布到 zhuxuekui3 solaris用户与文件权限管理1 类别    「网站分类」Oracle 一.用户与用户组管理 三种用户:超级用户. ...

  5. javaweb dev 入

    ::::关于jsp页面和servlet之间传递参数 JSP与 servlet之间的传值有两种情况:JSP -> servlet, servlet -> JSP. 通过对象 request和 ...

  6. POJ 3580(SuperMemo-Splay区间加)[template:Splay V2]

    SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11384   Accepted: 3572 Case T ...

  7. 网页编程-django前传

    1.js正则表达式  http://www.cnblogs.com/wupeiqi/articles/5602773.html test  - 判断字符串是否符合规定的正则 正则表达式: rep = ...

  8. VMware安装ubuntu学习笔记(只是笔记)

    VMware安装ubuntu开机黑屏/死机 1- Edit Ubuntu VM Configuration file (.vmx) 2- Add the following line cpuid.1. ...

  9. oracle sql修改序列为当前序列开始

    declare   v_num integer;  last_value integer;Begin  select SEQ_TBM_ID.NEXTVAL into last_value from d ...

  10. unity 接触一个月的感受和心得

    unity scrollview 遇到的问题 一个scrollview作为翻页,这样的效果调整. 一页上面有三个scrollview,这三个scrollview上的items不受下层整个页面的scro ...