Doing Homework

题目抽象:给出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的更多相关文章

  1. hdu1074 Doing Homework(状态压缩DP Y=Y)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  2. HDU 1074 Doing Homework (状态压缩 DP)

    题目大意: 有 n 项作业需要完成,每项作业有上交的期限和需完成的天数,若某项作业晚交一天则扣一分.输入每项作业时包括三部分,作业名称,上交期限,完成所需要的天数.求出完成所有作业时所扣掉的分数最少, ...

  3. HDU1074 Doing Homework 状态压缩dp

    题目大意: 根据完成任务的截止时间,超时一天罚1分,求完成所有任务后的最小罚时 这里n最大为15,可以利用状态压缩来解决问题 /* 首先要明白的一点是状态1/0分别表示这件事做了还是没做 而1/0的位 ...

  4. 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 ...

  5. HDU 1074 Doing Homework(状态压缩DP)

    题意:有n门课,每门课有截止时间和完成所需的时间,如果超过规定时间完成,每超过一天就会扣1分,问怎样安排做作业的顺序才能使得所扣的分最小 思路:二进制表示. #include<iostream& ...

  6. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  7. HDU1074(KB12-D 状态压缩dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. HDU1074(状态压缩DP)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. HDU_1074_Doing Homework_状态压缩dp

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. Spark RDD概念学习系列之RDD的创建(六)

    RDD的创建  两种方式来创建RDD: 1)由一个已经存在的Scala集合创建 2)由外部存储系统的数据集创建,包括本地文件系统,还有所有Hadoop支持的数据集,比如HDFS.Cassandra.H ...

  2. WebBrowser的各种使用方法(未完待续)(XE8+WIN7)

    相关资料: 占时想不起来了,有时间我补上吧. 程序下载: http://download.csdn.net/detail/zhujianqiangqq/9666390 实例代码: unit Unit1 ...

  3. QListWidgetItem带上颜色的问题

    new_item = QListWidgetItem(_fromUtf8(item_content), self.listWidget) 首先创建一个QListWidgetItem,第一个参数内容是I ...

  4. 将表A的数据复制到表B,以及关于主表和子表的删除办法

    如果表A的数据结构和表B的数据结构是一样的,字段名字可以不用相同,但是对应的数据类型是一样的 这样的情况下可以用如下的方式实现将表A的数据复制到表B INSERT INTO #TEMP2 SELECT ...

  5. Base64把图片、文件转码成字符串(互转)

    文件Base64以后会翻倍的涨,例如一张52kb的图片 base64以后string文件大小为185kb,在通过string转回图片为135kb   图片转文字: UIImage *_originIm ...

  6. 检查.net代码中占用高内存函数(翻译)

    哈哈,昨天没事做,在CodeProject瞎逛,偶然看到这篇文章,居然读得懂,于是就翻译了一下,当练习英语,同时增强对文章的理解,发现再次翻译对于文章的一些细节问题又有更好的理解.下面是翻译内容,虽然 ...

  7. 使用 EasyMock 更轻松地进行测试

    from:http://www.ibm.com/developerworks/cn/java/j-easymock.html 测试驱动开发是软件开发的重要部分.如果代码不进行测试,就是不可靠的.所有代 ...

  8. IE6/IE7/IE8 FF常见问题解决

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-04-08) <style type="text/css" > *{ margin:0px a ...

  9. PL/pgSQL学习笔记之三

    http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1.2. Supported Argument and Resul ...

  10. [转]O(n)回文子串算法 Manacher算法

    这里,我介绍一下O(n)回文串处理的一种方法.Manacher算法.原文地址:http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear- ...