这题比较有意思,暴力搜索必然tle,可以用状态压缩dp解决。

我们先不考虑完成所有作业的扣分,而考虑其一个子集的情况。

假设我们得到了完成某子集S对应的作业最少扣分,我们试着向该子集中增加一个元素a,那么我们将得到一个新的集合S1。

从而f(S1) = min(g(S')),  S'⊂S, 且#(S') = #(S) - 1。

其中g函数仅依赖于集合S'与元素e = (S - S')。

如果我们能够在处理S之前将其所有真子集都处理完毕,那么S可以直接由原状态导出。

于是当更新到S为全集的时候,答案也就得到了。

考虑用二进制表示状态,二进制数某一位为1或0代表同位次的元素属于(不属于)该集合。

所有子集的数值大小都比原集合小。

将二进制数从小到大扫描一遍即可。

这就是所谓的状态压缩dp。

复杂度O(n * 2^n)。

acm.hdu.edu.cn/showproblem.php?pid=1074
 
 
 #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
typedef __int64 LL; const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxm = << ; char s[][maxn];
int n, high;
struct Node{
int t, dl;
}node[maxn];
int dp[maxm];
int tc[maxm], pre[maxm], ans[]; void print(){
printf("%d\n", dp[high]);
int p = high, k = ;
while(p){
ans[k++] = pre[p];
p -= << pre[p];
}
for(int i = k - ; i >= ; i--) puts(s[ans[i]]);
} int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%s%d%d", s[i], &node[i].dl, &node[i].t);
}
high = ( << n) - ;
memset(dp, inf, sizeof dp);
dp[] = ;
for(int i = ; i <= high; i++){
for(int j = n - ; j >= ; j--){
int tem = << j;
//update the current state by enumerating the new element
if(tem & i){
//i is the current state while (i - tem) is the previous state
int p = max(, node[j].t + tc[i - tem] - node[j].dl);
if(p + dp[i - tem] < dp[i]){
dp[i] = p + dp[i - tem];
tc[i] = node[j].t + tc[i - tem];
pre[i] = j;
}
}
}
}
print();
}
return ;
}

hdu1074 Doing Homework的更多相关文章

  1. 状态压缩-----HDU1074 Doing Homework

    HDU1074 Doing Homework 题意:给了n个家庭作业,然后给了每个家庭作业的完成期限和花费的实践,如果完成时间超过了期限,那么就要扣除分数,然后让你找出一个最优方案使扣除的分数最少,当 ...

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

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

  3. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

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

  4. HDU1074 Doing Homework —— 状压DP

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

  5. HDU1074 Doing Homework 状态压缩dp

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

  6. HDU1074 Doing Homework(状压dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意:给定有n门课的作业,每门课交作业有截止时间,和完成作业所花费的时间,如果超过规定时间完成,每超 ...

  7. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  8. HDU1074:Doing Homework(状压DP)

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

  9. HDU 1074 Doing Homework (动态规划,位运算)

    HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...

随机推荐

  1. CSS位置如何获取的

  2. javascript语法详解

    javascript语法:运算符 条件语句if...else...  条件语句switch  循环语句for  循环语句while   跳转语句 js运算符 1.算数运算符:+ - * % / ++ ...

  3. C++之路进阶——codevs2404(糖果)

    2404 糖果 2011年省队选拔赛四川  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master     题目描述 Description 幼儿园里有N个小朋友,l ...

  4. 卸载了mysql之后,mysql服务仍在,显示读取描述失败,错误代码2

    卸载了mysql之后,mysql服务仍在,显示读取描述失败,错误代码2 用360软件管家,卸载mysql5.5,卸载了mysql之后,再依次删除 mysql的安装目录.c盘下的隐藏文件夹Program ...

  5. angular 自定义指令 link or controller

    Before compilation? – Controller After compilation? – Link var app = angular.module('plunker', []); ...

  6. ssh-copy-id帮你建立信任

    一.ssh-keygen -t rsa [nameA@machineA]$ ssh-keygen -t rsa Generating public/private rsa key pair. Ente ...

  7. 夺命雷公狗ThinkPHP项目之----企业网站5之栏目的添加(主要是图片上传)

    我们照老,先老搞定控CategoryController.class.php制器,代码如下所示: <?php namespace Admin\Controller; use Think\Cont ...

  8. 夺命雷公狗---微信开发58----微网站之jquery_mobile之控件介绍

    我们上一节课里面介绍了基本的jqm是如何用的了,那么这一节课我们就开始玩玩他的控件 1...布局网格 <!DOCTYPE html> <html> <head> & ...

  9. 解决windows的控制台显示utf8乱码的问题

    在控制台的属性里 修改自体为: 新宋体 在控制台下执行命令: chcp 65001

  10. HOWTO Install the MinGW (GCC) Compiler Suite

    Posted July 25th, 2008 by mingwadmin getting started install mingw Automated Installer If you are ne ...