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][ ...
随机推荐
- 金山面试CDN
History 今天去金山网络面试的时候,被问到性能优化,我说了几个.最后说到了CDN,我说要尽量把静态的内容放置到CDN,可是为什么呢?面试官说既然你说到CDN.你就说说它的原理. 之前有看过,可是 ...
- idea2018注册方法
下面是具体的破解激活步骤: 1. 下载破解补丁文件,路径为:http://idea.lanyus.com/jar/JetbrainsCrack-2.7-release-str.jar 2.将补丁放在安 ...
- scp windows 和 linux 远程复制 (双向)
一下命令在cmd中 从w -> l : scp D:\a.txt root@192.168.2.113:/home/a 从l -> w: scp root@192.168.2.113:/h ...
- HMM MEMM CRF 差别 联系
声明:本文主要是基于网上的材料做了文字编辑,原创部分甚少.參考资料见最后. 隐马尔可夫模型(Hidden Markov Model.HMM),最大熵马尔可夫模型(Maximum Entropy Mar ...
- Django+uwsgi+nginx+angular.js项目部署
这次部署的前后端分离的项目: 前端采用angular.js,后端采用Django(restframework),他俩之间主要以json数据作为交互 Django+uwsgi的配置可以参考我之前的博客: ...
- angularJS 自定义指令 分页
原理和使用说明 1.插件源码主要基于angular directive来实现. 2.调用时关键地方是后台请求处理函数,也就是从后台取数据. 3.插件有两个关键参数currentPage.itemsPe ...
- lua 字符串处理
匹配模式(pattern) . 任何单个字符 %a 任何字母 %c 任何控制字符 %d 任何数字 %g 任何除空白符外的可打印字符 %l 所有小写字母 %p 所有标点符号 %s 所有空白字符 %u 所 ...
- h5的复制功能
js+html5实现复制文字按钮 <div> <input type="text" name="guanfangaddress" id=&qu ...
- 基于Kubernetes 构建.NET Core技术中台
今天下午在腾讯云+社区社区分享了<基于Kubernetes 构建.NET Core技术中台>,下面是演讲内容的文字实录. 我们为什么需要中台 我们现在处于企业信息化的新时代.为什么这样说呢 ...
- mac下执行文件出现Permission Denied的解决
mac 下终端访问文件出现“Permission Denied”解决方案: 一个文件有3种权限,读.写.可执行,你这个文件没有可执行权限,需要加上可执行权限. 1. 终端下先 cd到该文件的目录下 2 ...