有n个任务,每个任务有一个截止时间,超过截止时间一天,要扣一个分。
求如何安排任务,使得扣的分数最少。Input有多组测试数据。第一行一个整数表示测试数据的组数
第一行一个整数n(1<=n<=15)
接下来n行,每行一个字符串(长度不超过100)表示任务的名称和两个整数,分别表示任务的截止时间和完成任务需要的天数。 这n个任务是按照字符串的字典序从小到大给出。Output每组测试数据,输出最少扣的分数的。 并输出一个完成任务的方案,如果有多个方案,输出字典序最小的一个。Sample Input

2
3
Computer 3 3
English 20 1
Math 3 2
3
Computer 3 3
English 6 3
Math 6 3

Sample Output

2
Computer
Math
English
3
Computer
English
Math

思路:数据范围可以状态压缩,dp[i]表示i状态下的最小扣分,状态转移为dp[i] = min(dp[pre]+dp[pre].time-limit[j]),dp[pre].time表示pre状态下花费的总时间,j表示状态pre转移到i时是经过哪一个中间态,即:pre = i^(1<<j)

const int maxm = (<<)+;

int finish[], limit[], n;

struct Node {
int fa, task, ans, time;
} dp[maxm]; map<int, string> Cache; void run_case() {
Cache.clear();
string str;
cin >> n;
for(int i = ; i < n; ++i) {
cin >> str >> limit[i] >> finish[i];
Cache[i] = str;
}
for(int i = ; i < (<<n); ++i) {
dp[i].ans = 0x3f3f3f3f;
for(int j = n-; j >= ; --j) {
if(i&(<<j)) {
int pre = i^(<<j);
int now = dp[pre].time+finish[j]-limit[j];
if(now < ) now = ;
if(now+dp[pre].ans<dp[i].ans) {
dp[i].fa = pre;
dp[i].task = j;
dp[i].ans = now+dp[pre].ans;
dp[i].time = dp[pre].time + finish[j];
}
}
}
}
int End = (<<n)-;
cout << dp[End].ans << "\n";
vector<int> ans;
while(End) {
ans.push_back(dp[End].task);
End = dp[End].fa;
}
for(auto i = ans.rbegin(); i != ans.rend(); ++i) {
cout << Cache[*i] << "\n";
}
return;
} int main() {
ios::sync_with_stdio(false), cin.tie();
int T;
cin >> T;
while(T--) {
run_case();
}
return ;
}

Day9 - G - Doing Homework HDU - 1074的更多相关文章

  1. Doing Homework HDU - 1074 (状压dp)

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

  2. Doing Homework HDU - 1074

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

  3. D - Doing Homework HDU - 1074 (状压dp)

    题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求  10 ...

  4. Doing Homework HDU - 1074 状态压缩

    #include<iostream> #include<cstring> #include<cstdio> #include<string> #incl ...

  5. 【状态DP】 HDU 1074 Doing Homework

    原题直通车:HDU  1074  Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...

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

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

  7. E - Tunnel Warfare HDU - 1540 F - Hotel G - 约会安排 HDU - 4553 区间合并

    E - Tunnel Warfare HDU - 1540 对这个题目的思考:首先我们已经意识到这个是一个线段树,要利用线段树来解决问题,但是怎么解决呢,这个摧毁和重建的操作都很简单,但是这个查询怎么 ...

  8. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  9. HDU 1074:Doing Homework(状压DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Problem Description Ignatius has just ...

随机推荐

  1. POJ 1204 Word Puzzles(AC自动机)

    这题的数据卡在,如下: 5 5 3 ABCDE FGHIJ KLMNO PQRST UVWXY PQR RS RST puzzle中间的行中可以包含要查询的多个单词.这个问题很好解决,SearchDf ...

  2. python中的type和object详解

    关于这篇博客 这篇博客主要描述Python的新风格对象(new-style objects),如下: <type 'type'>和<type 'object'>分别是什么? 用 ...

  3. 解决mysql和navicat乱码问题

    1,首先进入mysql的my.ini文件,进行编码修改,全部改成utf8编码(这里就不赘述了,网上一搜一堆) 2,最重要的一点,把原先navicat创建的连接断开,重新创建新连接,在该新连接下创建库, ...

  4. VUE组件 单独文件封装

    https://www.cnblogs.com/SamWeb/p/6391373.html vuejs 单文件组件.vue 文件   vuejs 自定义了一种.vue文件,可以把html, css, ...

  5. java怎么调用子类中父类被覆盖的方法

    public class b { { void show() { System.out.println("b"); } } public class c extends b { v ...

  6. 树莓派4B踩坑指南 - (6)安装常用软件及相关设置

    安装软件 安装LibreOffice中文包 sudo apt-get install libreoffice-l10n-zh-cn sudo reboot 安装codeblocks并汉化: sudo ...

  7. [ DLPytorch ] 批量归一化与残差网络

    批量归一化 通常来说,数据标准化预处理对于浅层模型就足够有效了.随着模型训练的进行,当每层中参数更新时,靠近输出层的输出较难出现剧烈变化.但对深层神经网络来说,即使输入数据已做标准化,训练中模型参数的 ...

  8. 15、python面对对象之类和对象

    前言:本文主要介绍python面对对象中的类和对象,包括类和对象的概念.类的定义.类属性.实例属性及实例方法等. 一.类和对象的概念 问题:什么是类?什么是实例对象? 类:是一类事物的抽象概念,不是真 ...

  9. git pull 之后怎么找回别覆盖掉的内容

    [半夜吓出冷汗,git这个原理还真得好好学学] 不小心把本地写的东西pull了下,然后,全部覆盖掉了,以为就这样没了. 后面想到有“时光穿梭机”,“历史回滚”,在各大群友的帮助下,终于找回了. git ...

  10. SpringBoot+JWT+SpringSecurity+MybatisPlus实现Restful鉴权脚手架

    若图片查看异常,请前往掘金查看:https://juejin.im/post/5d1dee34e51d4577790c1cf4 前言 JWT(json web token)的无状态鉴权方式,越来越流行 ...