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
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
随机推荐
- 【hyperscan】示例解读 pcapscan
示例位置: <hyperscan source>/examples/pcapscan.cc参考:http://01org.github.io/hyperscan/dev-reference ...
- ES6中的元编程-Proxy & Reflect
前言 ES6已经出来好久了,但是工作中比较常用的只有let const声明,通过箭头函数改this指向,使用promise + async 解决异步编程,还有些数据类型方法...所以单独写一篇文章学习 ...
- Python code 提取UML
Python是一门支持面向对象编程的语言,在大型软件项目中,我们往往会使用面向对象的特性去组织我们的代码,那有没有这样一种工具,可以帮助我们从已有代码中提取出UML图呢?答案是有的.以下,我们逐个介绍 ...
- SDK 上报信息 史上最全 持续更新
SDK 上报信息 史上最全 持续更新 接入SDK总会遇到各种需求,有些SDK巴不得把玩家信息全部上报到他们服务器! 以下是我接SDK遇到的, 欢迎大家补全. 上报事件 注册(按道理这个应该是SDK的功 ...
- 【learning】 扩展lucas定理
首先说下啥是lucas定理: $\binom n m \equiv \binom {n\%P} {m\%P} \times \binom{n/P}{m/P} \pmod P$ 借助这个定理,求$\bi ...
- [Leetcode]316.去除重复字母
题目 贪心方法 用一个两个数组vector<int>cnt,vector<bool>in_right_place: string res:目前符合条件的字符串,到代码结束的时候 ...
- JSPatch动态更新APP
JSPatch,只需在项目中引入极小的引擎,就可以使用JavaScript调用任何Objective-C的原生接口,获得脚本语言的能力:动态更新APP,替换项目原生代码修复bug. 用途 是否有过这样 ...
- 最大子数组问题/Maximum Subarray
问题描述: Find the contiguous subarray within an array (containing at least one number) which has the la ...
- 复刻smartbits的国产网络测试工具minismb-网络连接数测试方法
复刻smartbits的网路性能测试工具MiniSMB,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此工具测试任何ip网络设备的端口吞吐率,带宽,并发连接数和最 ...
- Centos7下使用yum安装lnmp zabbix3.2
1:配置epel-release mysql zabbix 源 配置epel源 wget http://mirrors.aliyun.com/epel/epel-release-latest-7.no ...