Doing Homework 状态压缩DP
题目抽象:给出n个task的name,deadline,need。 每个任务的罚时penalty=finish-deadline; task不可以同时做。问按怎样的顺序做使得penalty最小。同时输出顺序。如果有多个满足条件的顺序,按字典序输出。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef long long LL;
const int INF=0x5fffffff;
const double EXP=1e-;
const int MS=; struct task
{
char name[];
int deadline,need;
}tasks[MS]; struct node
{
int time,penalty; // 到达这个状态的时间,和罚时
int cur,pre; // 状态s的物理变化过程
}nodes[<<MS]; int n,m; void solve()
{
for(int i=;i<=m;i++) // note i==1
nodes[i].penalty=INF;
nodes[].time=;
for(int i=;i<=m;i++)
{
for(int j=;j<n;j++)
if(!((i>>j)&))
{
int next=i|(<<j);
int finish=nodes[i].time+tasks[j].need;
int penalty=max(,finish-tasks[j].deadline);
penalty+=nodes[i].penalty;
if(penalty<nodes[next].penalty)
{
nodes[next].time=finish;
nodes[next].penalty=penalty;
nodes[next].cur=j;
nodes[next].pre=i;
}
}
}
} void output(int x)
{
if(x==)
return ;
output(nodes[x].pre);
printf("%s\n",tasks[nodes[x].cur].name);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%s%d%d",tasks[i].name,&tasks[i].deadline,&tasks[i].need);
m=(<<n)-;
solve();
printf("%d\n",nodes[m].penalty);
output(m);
}
return ;
}
Doing Homework 状态压缩DP的更多相关文章
- hdu1074 Doing Homework(状态压缩DP Y=Y)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1074 Doing Homework (状态压缩 DP)
题目大意: 有 n 项作业需要完成,每项作业有上交的期限和需完成的天数,若某项作业晚交一天则扣一分.输入每项作业时包括三部分,作业名称,上交期限,完成所需要的天数.求出完成所有作业时所扣掉的分数最少, ...
- HDU1074 Doing Homework 状态压缩dp
题目大意: 根据完成任务的截止时间,超时一天罚1分,求完成所有任务后的最小罚时 这里n最大为15,可以利用状态压缩来解决问题 /* 首先要明白的一点是状态1/0分别表示这件事做了还是没做 而1/0的位 ...
- D - Doing Homework 状态压缩 DP
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...
- HDU 1074 Doing Homework(状态压缩DP)
题意:有n门课,每门课有截止时间和完成所需的时间,如果超过规定时间完成,每超过一天就会扣1分,问怎样安排做作业的顺序才能使得所扣的分最小 思路:二进制表示. #include<iostream& ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- HDU1074(KB12-D 状态压缩dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU1074(状态压缩DP)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU_1074_Doing Homework_状态压缩dp
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- vim之vba文件
[vim之vba文件] Vimball 官方描述: The vimball plugin facilitates creating, extracting , and listing the cont ...
- NSInvocation Basics
In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Appl ...
- Android Service服务
Service是Android系统中提供的四大组件之一.它是运行在后台的一种服务,一般声明周期较长,不直接与用户进行交互. 服务不能自己运行,需要通过调用Context.startService ...
- C# try catch finally 执行
try { //dosomething eg: int a = 1; int b = 2; int c = a + b; if(c>2) { return; } } catch(Exceptio ...
- 面试过程中javascript原型链与作用域的问题
现在校招也基本结束了,所以有时间把这段时间遇到的问题做个总结.在很多的笔试题目中,发现有很多对JS作用域方面的考察,所以查阅资料总结一下. 众所周知,js不像其他OOP语言那样,他是一种弱类型的语言, ...
- 初步认识shell
言语不多说,直奔主题,lz不善于写文章,只是记录自己学习过程中的点点滴滴. 注意:shell对于字母大小写比较敏感. 打开终端出现:username@hostname$或者root@hostname# ...
- baseDao 使用spring3+hibernate3方式
package cn.zk.pic.service.dao; import java.io.Serializable; import java.util.List; import java.util. ...
- Extjs 实现输入数量,实时更改总价
// 总价 var totalNum = '0.00'; //总价初始值 var $total = new Ext.form.Label({ text: '消费金额 : ¥' + totalNum + ...
- Uva110 Meta-Loopless Sorts
Meta-Loopless Sorts Background Sorting holds an important place in computer science. Analyzing and i ...
- wpa_supplicant 移植及 linux 命令行模式配置无线上网
本文涉及内容为linux 命令行模式配置无线上网 及 wpa_supplicant 移植到开发板的过程,仅供参考. 1.源码下载 wpa_supplicant 源码下载地址 :http://hosta ...