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
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
随机推荐
- Distinct Substrings(spoj694)(sam(后缀自动机)||sa(后缀数组))
Given a string, we need to find the total number of its distinct substrings. Input \(T-\) number of ...
- 【入门推荐】SQL注入进行WebShell渗透测试的基础概览
作者:zero 本文为SQL基本注入的进阶文章,如有任何疑问请查看: SQL基本注入演示:https://www.cnblogs.com/anbus/p/10082452.html 导语: 利用SQL ...
- Tools - Others
01 - 一些网络工具 文档查阅 https://devdocs.io/ API文档 http://overapi.com/ 开源代码及文档搜索 https://searchcode.com/ 电子书 ...
- MySQL查询50例
创建表和关系 /* 创建表 */ /*年级表*/ DROP TABLE IF EXISTS `class_grade`; CREATE TABLE `class_grade` ( `gid` int( ...
- String.format(String format,Object... args)的用法
String.format(String format, Object... args)方法详解 以前也看到过很多次这个用法,一直记不牢靠,今天整理一下. 我仅仅举几个例子稍做说明: String ...
- opencv2函数学习之blur,GaussianBlur,medianBlur和bilateralFilter:实现图像平滑处理
在opencv2中,可能使用blur对图像进行平滑处理,这种方法就是最简单的求平均数. 平滑 也称 模糊, 是一项简单且使用频率很高的图像处理方法. 平滑处理的用途有很多, 但是在很多地方我们仅仅关注 ...
- 设置ListView显示到最后一行
上次聊天的那个界面上用的一个TextView,然后每次消息都用text.append("消息内容"+"\n")函数来在text字符串后边接一段,然后重新显示这个 ...
- PLSQL Developer是什么?
不多说,直接上干货! PLSQL Developer是一款可以帮助用户管理Oracle数据库开发存储程序单元的集成开发环境IDE,通过该软件,用户可以编辑.编译.纠正.测试.调试.优化.查询您的数据信 ...
- 《Java多线程编程核心技术》——多线程与同步
Java多线程 线程可以理解为是在进程中独立运行的子任务. Java多线程 使用方法 Java中实现多线程主要有以下两种方法: 继承Thread,而后实例化该对象调用start()即启动了新线程; 实 ...
- redis cluster集群管理工具redis-trib.rb命令小结-运维笔记
redis-trib.rb是redis官方推出的管理redis集群的工具,集成在redis的源码src目录下,是基于redis提供的集群命令封装成简单.便捷.实用的操作工具.redis-trib.rb ...