HDU1074(KB12-D 状态压缩dp)
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8756 Accepted Submission(s): 4065
Problem Description
Input
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
Sample Input
3
Computer 3 3
English 20 1
Math 3 2
3
Computer 3 3
English 6 3
Math 6 3
Sample Output
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.
//2017-03-28
//状态压缩dp,sta的二进制所在位为1表示对应的作业已经处理,0表示未处理。sta低位对应为字典序小的课程。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack> using namespace std; const int N = (<<)+;
const int inf = 0x3f3f3f3f;
int pre[N];//pre[i]表示状态i由前一个状态转移来时放入的作业编号
int dp[N];//dp[i]表示达到状态i所扣的最少的分
int tm[N];//tm[i]表示到达状态i花费的最少时间
int order[];//用于保存最后输出的课程序列
int n;
struct node
{
string name;
int d, c;
}work[]; int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
for(int i = ; i < n; i++)
cin>>work[i].name>>work[i].d>>work[i].c;
for(int sta = ; sta < (<<n); sta++)
{
dp[sta] = inf;
for(int j = n-; j >= ; j--)//为使序列倒序输出,从字典序大的作业开始枚举
{
int fmsta = (<<j);//表示当前状态sta可以由sta-fmsta状态转移而来。
if(!(fmsta&sta))continue;//表示该sta-fmsta不能转移到sta,继续
int score = tm[sta-fmsta] - (work[j].d - work[j].c);//tm[sta-fmsta]表示转移前状态所花费的最小时间,(work[j].d - work[j].c)表示work[j]能开始的最晚时间。
if(score < )score = ;//若转移前时间比最晚开始时间早,所需要扣的分为0
if(dp[sta] > dp[sta-fmsta]+score){
dp[sta] = dp[sta-fmsta]+score;
tm[sta] = tm[sta-fmsta] + work[j].c;
pre[sta] = j;
}
}
}
cout<<dp[(<<n)-]<<endl;
int cnt = , pos = (<<n)-;
stack<int> s;
while(pos)
{
s.push(pre[pos]);
pos = pos-(<<pre[pos]);
}
while(!s.empty())
{
cout<<work[s.top()].name<<endl;
s.pop();
}
} return ;
}
HDU1074(KB12-D 状态压缩dp)的更多相关文章
- hdu1074 Doing Homework(状态压缩DP Y=Y)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU1074 Doing Homework 状态压缩dp
题目大意: 根据完成任务的截止时间,超时一天罚1分,求完成所有任务后的最小罚时 这里n最大为15,可以利用状态压缩来解决问题 /* 首先要明白的一点是状态1/0分别表示这件事做了还是没做 而1/0的位 ...
- HDU1074(状态压缩DP)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu1074 状态压缩dp+记录方案
题意: 给你一些作业,每个作业有自己的结束时间和花费时间,如果超过结束时间完成,一天扣一分,问你把n个作业完成最少的扣分,要求输出方案. 思路: 状态压缩dp,记录方案数的地方 ...
- 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
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
随机推荐
- [vuejs] vue2.0-layer-mobile移动端弹层
vue2.0-layer-mobile移动端弹层 本次组件升级支持slot内容分发功能,实现高定制内容风格的弹层 安装方法 npm install vue2-layer-mobile -S 初始化 i ...
- [ActionScript 3.0] 有必要记录一下:flash builder运用Animate CC 发布的swc的一个奇葩问题,亲测
之前一直用flash cs6 发布swc 配合flash builder4.6开发,最近用Animate CC发布swc,却出现无法flash builder4.6 无法连接到调试器的问题, 经过反复 ...
- 使用Flexbox:新旧语法混用实现最佳浏览器兼容
Flexbox非常的棒,肯定是未来布局的一种主流.在过去的几年这之中,语法改变了不少,这里有一篇“旧”和“新”新的语法区别教程(如果你对英文不太感兴趣,可以移步阅读中文版本).但是,如果我们把Flex ...
- CentOS7安装MYSQL。
参考这个文章(网页已存到本地):http://www.cnblogs.com/starof/p/4680083.html 安装完成后,本地登录MYSQL没有问题. 现在主要是在windows下用ora ...
- DevOps - CI - Sonar
Sonar 官方信息 https://www.sonarqube.org/ https://www.sonarqube.org/downloads/ https://docs.sonarqube.or ...
- [原创]Base32加密解密工具
工具: Base32_Decode编译: VS2012 C# (.NET Framework v2.0)组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8. ...
- sql必知必会
1.根据条件查询数据库中数据,并返回数据条数 去掉count就会返回数据库中符合条件的所有数据 SELECT COUNT(*) FROM sentiment_info WHERE sentiment_ ...
- Identity Server4学习系列一
一.前言 今天开始学习Identity Server4,顺便了解下.Net Core,以便于完善技术栈,最主要的是要跟上.Net的发展潮流,顺便帮助各位整理下官方文档,加上一些我自己对他的理解. 这是 ...
- Notepad++中代码格式化插件NppAStyle
本文以图片和说明,手把手教大家怎么让Notepad++中的代码风格看起来更美观. 工具/原料 Windows7 Notepad++ NppAStyle(Notepad++的一个插件) 方法/步骤 直 ...
- react + react-router + less +antd 开发环境
react + react-router + less +antd 开发环境搭建 1.基于create-reacte-app,需要先安装这个脚手架,然后初始化项目. 2.进入项目目录,首先 npm r ...