有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. systomctl与service的区别主要是版本区别

    redhat和centos在7及以后的版本,用systemctl命令 redhat和centos在6及6以前的版本,用service命令. 两者的区别,如下. 举例 这里的.service可以不写,如 ...

  2. werkeug的WSGI服务器解析

    werkeug的WSGI服务器解析 1.      WSGI 1.1.    wsgi与flask flask默认的wsgi引用自wekurg 声明app:FLASK对象 app.run() run_ ...

  3. hadoop集群启动报错: java.io.IOException: Incompatible clusterIDs

    java.io.IOException: Incompatible clusterIDs in /export/hadoop-2.7.5/hadoopDatas/datanodeDatas2: nam ...

  4. Kubernetes的pod控制器之DaemonSet

    DaemonSet 顶级参数介绍 [root@master manifests]# kubectl explain ds KIND: DaemonSet VERSION: extensions/v1b ...

  5. 8个问题看你是否真的懂 JS

    文章转载: https://juejin.im/post/5d2d146bf265da1b9163c5c9#heading-20 原文地址: https://dev.to/aman_singh/so- ...

  6. Cat4500升级注意事项

    第一部分:升级ROMMON 可以通过release note去查看什么Supervisor建议什么样的版本.例如:ROMMON Release Notes for the WS-X45-SUP7-E, ...

  7. ASA设置某些log不发送到log server

    If you want to suppress a specific syslog message to be sent to syslog server, then you must enter t ...

  8. JS获取光标在input 或 texterea 中下标位置

    <textarea placeholder="请输入表达式" id="methodInput" ></textarea> 获取位置: v ...

  9. 关于调用接口 Connection reset 问题(使用代理调接口)

    之前调用过别的公司的接口上传数据,但是遇到个问题就是Connection reset,查阅了网上的各种资料,说什么的都有,主要意思就是说发布接口和调用接口的某些配置不一样,但是这个怎么说呢,单方面没办 ...

  10. 「Luogu P5368 [PKUSC2018]真实排名」

    PKUSC签到题 题目大意 给出一个长度为 \(N\) 的序列,序列中有 \(K\) 个数会乘二,对于每个数计算在乘二后大于等于这个数的个数与乘二前没有发生变化的方案数. 分析 思路很清晰,可以将答案 ...