HDU 1074 Doing Homework
第一次做这道题大概是半个月前了吧,状压DP一个很新鲜的名词
当时看题解怎么也看不懂,现在看懂了以后还是很简单的
所谓状态压缩就是用一个整数的二进制来表示一个状态,比如有三个作业
000表示一科作业也没做,001表示只做了第一科,111表示三科作业都做了
那么从状态0开始出发,遍历每一个状态,如果对于状态S有第i科作业没写那么计算该状态下做完第i科作业对应的扣分数,如果比别人状态下转移过来的扣分数要少,那么状态S就是下一个状态的前驱
用结构体里的pre来保存路径
最后输出科目的时候用递归输出,也是一种很常用的方法
//#define LOCAL
#include <cstdio>
#include <cstring> const int maxn = ( << );
struct Node
{
int used;
int pre;
int reduced;
}dp[maxn]; struct Course
{
int deadline;
int cost;
char name[];
}course[]; bool vis[maxn]; void OutPut(int S)
{
int t = S ^ dp[S].pre;
int i = -;
while(t)
{
t >>= ;
++i;
}
if(dp[S].pre != )
OutPut(dp[S].pre);
printf("%s\n", course[i].name);
} int main(void)
{
#ifdef LOCAL
freopen("1074in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%s%d%d", course[i].name, &course[i].deadline, &course[i].cost);
memset(vis, false, sizeof(vis));
vis[] = true;
dp[].used = , dp[].pre = -, dp[].reduced = ;
int All = ( << n) - ;
for(int S = ; S < All; ++S)
for(int i = ; i < n; ++i)
{
if((S & ( << i)) == )
{//S状态下第i项作业还没做
Node temp;
int next = S | ( << i);
temp.used = dp[S].used + course[i].cost;
temp.pre = S;
temp.reduced = temp.used - course[i].deadline;
if(temp.reduced < ) temp.reduced = ;
temp.reduced += dp[S].reduced; if(vis[next] && temp.reduced < dp[next].reduced)
dp[next] = temp;
else if(!vis[next])
{
vis[next] = true;
dp[next] = temp;
}
}
} printf("%d\n", dp[All].reduced);
OutPut(All);
}
return ;
}
代码君
HDU 1074 Doing Homework的更多相关文章
- 【状态DP】 HDU 1074 Doing Homework
原题直通车:HDU 1074 Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...
- HDU 1074 Doing Homework (动态规划,位运算)
HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- HDU 1074 Doing Homework【状态压缩DP】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意: 给定作业截止时间和完成作业所需时间,比截止时间晚一天扣一分,问如何安排作业的顺序使得最 ...
- HDU 1074 Doing Homework(像缩进DP)
Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...
- HDU 1074 Doing Homework (状态压缩DP)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- HDU 1074 Doing Homework(经典状压dp)
题目链接 Doing Homework Ignatius has just come back school from the 30th ACM/ICPC. Now he has a ...
- HDU 1074 Doing Homework 状压dp(第一道入门题)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- JS中showModalDialog 详细使用(转)
基本介绍: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showModalDial ...
- eclipse git 整合
最近朋友都推荐使用github管理自己的项目,而且免费用户可以有5个仓库,恰好我也想了解下git,借此机会学习一下.github官方指南使用独立第三方git工具来进行版本控制,并不借助于eclipse ...
- Sqli-labs less 26a
Less-26a 这关与26的区别在于,sql语句添加了一个括号,同时在sql语句执行抛出错误后并不在前台页面输出.所有我们排除报错注入,这里依旧是利用union注入. sql语句为SELECT * ...
- 金融证券协议FIX/FAST/STEP
金融信息交换协议FIX是适用于实时证券.金融电子交易的数据通信标准.它是把各类证券金融业务需求流程格式化,使之成为一个可用计 算机语言描述的功能流程,并在每个业务功能接口上统一交换格式.STEP(Se ...
- 请教DotNetBar控件中的CalendarView控件如何拖动当前的时间轴
本人想拖动那个当前的时间轴或者让时间轴变动,因为那个时间轴默认的是当前时间.(就是那个黄色的线)
- POJ 2013
#include <iostream> #include <string> #define MAXN 20 using namespace std; string _m[MAX ...
- 关于com组件注册的问题
问题是这样的: 在调用摄像头的时候,用到com组件,我已经在工程中添加了com组件,但是运行的时候却报这样的错误. 解决方案:程序生成中,目标平台为Any CPU ,应该改为x86 具体原因不知道……
- (转)Android: NDK编程入门笔记
转自: http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html 为何要用到NDK? 概括来说主要分为以下几种情况: 1. 代 ...
- OSX Mavericks下使用Synergy进行多台主机通过wifi共享键鼠问题的解决方法
转帖: OSX 10.9 几天用下来还是遇到几处问题的:之前先是遇到了OSX Mavericks GM598无法从Appstore升级到完全正式版的问题,下载无反应,后来找到了解决方法,发在以下链接: ...
- wamp中的phpmyadmin打开出现:#1045 - Access denied for user 'root'@'localhost' (using password: NO)
详细内容: MySQL said: #1045 - Access denied for user 'root'@'localhost' (using password: NO) phpMyAdmin ...