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 ...
随机推荐
- IDE Plug
IDE Plug 使用 cnpack提供的IDE External Wizard Management 管理插件.添加插件.删除插件 Cnpack D:\Program Files (x86)\CnP ...
- c语言typedef的用法-解惑阿!很多天书般的东西解释的不错(转)
转自(http://www.cnblogs.com/wchhuangya/archive/2009/12/25/1632160.html) 一.基本概念剖析 int* (*a[5])(int, cha ...
- 做fzu oj 1045 做减法学到的sprintf()函数
题目 做题一直输不出答案,于是就上网去百度了这题的解题,发现解答十分的简短,而且其中我看见了平时没见过的函数,sprintf(). 于是就百度sprintf()的使用. 如下: 函数功能:把格式化的数 ...
- Arduino 模拟信号的读入并转化为0-5V电压
int ledIn = A0; void setup(){ Serial.begin(9600); } void loop(){ int sensorValue = analogRead(ledIn) ...
- php redis 分布式类
配置: $redis_config = array( 'prefix' => 'ylmall_', 'master' => array( 'host' => "192.16 ...
- VTK序列图像的读取[转][改]
医学图像处理的应用程序中,经常会碰到读取一个序列图像的操作.比如CT.MR等所成的图像都是一个切面一个切面地存储的,医学图像处理程序要处理这些数据,第一步当然是把这些数据从磁盘等外部存储介质中导入内存 ...
- JSON初探
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...
- clientTop scrollTop offsetTop
关于top.clientTop.scrollTop.offsetTop的用法 网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.cli ...
- C++异常
相对于C语言,C++增加了异常机制.考虑,异常解决了什么问题,又带来了什么问题. 异常解决了什么问题: 1.问题检测与问题处理相分离. 2.C语言只是返回一个整数,而异常带有上下文信息,方便找出问题. ...
- cdoj 30 最短路 flyod
最短路 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/30 Descript ...