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 ...
随机推荐
- 【Cocos2d-X开发学习笔记】第18期:动作类之改变动作对象、函数回调动作以及过程动作的使用
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 一.改变动作执行对象 CCTargetedAct ...
- web.xml filter 顺序
The order the container uses in building the chain of filters to be applied for a particular request ...
- 删除对象中的key
delete obj.a; delete obj["a"];
- 欧几里德&扩展以及求解线性方程学习总结--附上poj1061解题报告
欧几里德算法: 欧几里德就是辗转相除法,调用这个gcd(a,b)这个函数求解a,b的最大公约数 公式: gcd(a,b)=gcd(b,a%b):并且gcd(a,b)=gcd(b,a)=gcd(-a,b ...
- WCF WEB API配置
Web.config配置 <system.serviceModel> <services> <service name="WCFServiceWebRole2. ...
- C++成员变量、构造函数的初始化顺序 [转]
C++成员变量.构造函数的初始化顺序 一.C++成员变量初始化 1.普通的变量:一般不考虑啥效率的情况下 可以在构造函数中进行赋值.考虑一下效率的可以再构造函数的初始化列表中进行 2.static 静 ...
- Sublime Text3 激活教程
Sublime Text3激活 在使用Sublime时会定期弹出购买提示框,避免出现购买提示,影响工作效率,我们可以使用网上的激活码,虽然有些不厚道,但是工作以后,一定选择购买正版支持一下. 打开Su ...
- (3)HTML ”列表“、图片和超链接
本节解说 1. html支持的列表:无序列表.有序列表.定义列表 2. html中如何插入图片 3.html的超链接 <1> 无序列表 无序列表是一个项目的列表,此列项目使用粗体圆点(典型 ...
- 【转】 Volley NegativeArraySizeException 解决
http://blog.csdn.net/very_caiing/article/details/46241531 今天在百度统计看项目上有一个crash比较高的bug: Java.lang.Nega ...
- Qtwebkit flashplayer插件问题
复制npswf32.dll 到 C:\WINDOWS\system32\Macromed\Flash\ 代码加入: //! [1] QNetworkProxyFactory::setUseSyst ...