HDU1074(状态压缩DP)
Doing Homework
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7070    Accepted Submission(s): 3104
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.
#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)的更多相关文章
- hdu1074 状态压缩dp+记录方案
		
题意: 给你一些作业,每个作业有自己的结束时间和花费时间,如果超过结束时间完成,一天扣一分,问你把n个作业完成最少的扣分,要求输出方案. 思路: 状态压缩dp,记录方案数的地方 ...
 - HDU1074(KB12-D 状态压缩dp)
		
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
 - hoj2662 状态压缩dp
		
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
 - POJ 3254 Corn Fields(状态压缩DP)
		
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
 - [知识点]状态压缩DP
		
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
 - HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
		
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
 - DP大作战—状态压缩dp
		
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
 - 状态压缩dp问题
		
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
 - BZOJ-1226     学校食堂Dining       状态压缩DP
		
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
 
随机推荐
- fastjson中Map与JSONObject互换,List与JOSNArray互换的实现
			
1.//将map转换成jsonObject JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(itemMap)); 将 ...
 - 安装mongoDB遇见的一个路径问题
			
如果安装路径不存在,则不会解压EXE软件! 安装monogoDB后,它不会自动添加执行路径! 意思就是安装路径是D盘下面的mongoDB文件夹,假如不存在这个文件夹,则不会安装成功 你需要添加路径: ...
 - table 设置边框
			
本文引自:https://www.cnblogs.com/leona-d/p/6125896.html 示例代码: <!DOCTYPE html> <html lang=" ...
 - EhCache Monitor的使用
			
1.在http://ehcache.org/documentation/monitor.html#Installation_And_Configuration下载ehcache-monitor-kit ...
 - Spark技术内幕: Task向Executor提交的源代码解析
			
在上文<Spark技术内幕:Stage划分及提交源代码分析>中,我们分析了Stage的生成和提交.可是Stage的提交,仅仅是DAGScheduler完毕了对DAG的划分,生成了一个计算拓 ...
 - ipython notebook 如何打开.ipynb文件?
			
标签: pythontensorflow 2017-03-29 14:17 235人阅读 评论(0) 收藏 举报 分类: TensorFlow(13) 转自:https://www.zhihu.c ...
 - openwrt spi flash 分区适配过程
			
openwrt spi flash 分区适配过程 这里基于 openwrt mt7620a 平台来跟踪,主要是想理清 dts 里的分区描述是如何一步步转化成内核分区行为. 先来看看 dts 中关于分区 ...
 - PythonCookBook笔记——文件与IO
			
文件与IO 所有的程序都要处理输入与输出,涉及到文本.二进制文件.文件编码和对文件名.目录的操作. 读写文本数据 需要读写各种不同编码的文本数据,使用rt模式的open()函数. 该读写操作使用系统默 ...
 - Linux 中权限控制实例
			
前言 前文对 Linux 中的权限进行了较为透彻的分析.而本文,则在前文的基础上,具体说明如何在代码中进行权限控制. 下面的代码涉及到以下几个方面: 1. 创建文件时设置文件权限 2. 修改文件的默认 ...
 - "Installing Software" has encountered a problem---pydev  on ubuntu
			
"Installing Software" has encountered a problem. An error occurred while collecting items ...