有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. PAT T1025 Keep at Most 100 Characters

    删除字符的镜像问题,状态转移方程一样~ #include<bits/stdc++.h> using namespace std; ; ; string s; long long dp[ma ...

  2. springboot @Select @Insert @Update @Delete

    https://blog.csdn.net/qq_20867981/article/details/80641353 使用@Select.@Insert.@Update.@Delete注解代替xxxM ...

  3. HYSBZ-2038小Z的袜子

    作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命-- 具体来说,小Z把这N只袜子从1到N编号,然后从 ...

  4. Hibernate学习(五)

    自关联测试案例 1.创建表 drop table if exists t_category ; create table t_category ( id ) primary key , name ) ...

  5. Cisco Packet Tracer 7.2

    Cisco Packet Tracer 7.2.1已于2018年12月28日发布,版本号为7.2.1.0218,现在可在Cisco Netacad网站上下载. What's new in Cisco ...

  6. [01]Binary Search二分查找

    Binary Search二分查找 作用:二分查找适用于有序的的数组或列表中,如果列表及数组中有n个元素,通过二分查找查询某一元素的位置需要的步骤是log2(n)(注:该log的底数是2) 1.Pyt ...

  7. pytoch 安装

    注意替换清华源,否则直接安装速度会很慢. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud ...

  8. [原]greenplum安装详细过程

    今天又帮其他项目装了一遍GP,加上之前的两次,这是第三次了,虽然每次都有记录,但这次安装还是发现漏写了一些步骤,在此详细记录一下,需要的童鞋可以借鉴. 1.准备 这里准备了4台服务器,1台做maste ...

  9. 爬虫(十四):Scrapy框架(一) 初识Scrapy、第一个案例

    1. Scrapy框架 Scrapy功能非常强大,爬取效率高,相关扩展组件多,可配置和可扩展程度非常高,它几乎可以应对所有反爬网站,是目前Python中使用最广泛的爬虫框架. 1.1 Scrapy介绍 ...

  10. Sonic_cli常用命令

    用户名:admin 密码:YourPaSsWoRd //change password1>admin@sonic:~$ passwdChanging password for admin.(cu ...