http://acm.hdu.edu.cn/showproblem.php?pid=1074

每个任务有一个截止日期和完成时间,超过截止日期一天扣一分,问完成全部任务最少扣几分,并输出路径

最多15个任务,状态压缩一下进行dp,输出路径的话要记录每种状态的前驱,存起来逆序输出

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <map>
  5. using namespace std;
  6.  
  7. const int INF = 0xfffffff;
  8.  
  9. struct fuck{
  10. int w, pre;
  11. }dp[<<];
  12.  
  13. struct node{
  14. char name[];
  15. int D, C;
  16. }p[];
  17.  
  18. int cal(int x){
  19. int res = , cnt = ;
  20. while(x){
  21. if(x & ){
  22. res += p[cnt].C;
  23. }
  24. cnt++;
  25. x >>= ;
  26. }
  27. return res;
  28. }
  29.  
  30. int cnt(int x){
  31. int res = ;
  32. while(x){
  33. if(x & ){
  34. res++;
  35. }
  36. x >>= ;
  37. }
  38. return res;
  39. }
  40.  
  41. int cal1(int x, int y){
  42. int res = ;
  43. while(){
  44. if((x&) != (y&)){
  45. return res;
  46. }
  47. res++;
  48. x >>= ; y >>= ;
  49. }
  50. }
  51.  
  52. int ans[], ct;
  53.  
  54. int main(){
  55. int T;
  56. scanf("%d", &T);
  57. while(T--){
  58. int n;
  59. scanf("%d", &n);
  60. for(int i = ; i < (<<n); i++)
  61. dp[i].w = INF;
  62. int xx = ;
  63. while(){
  64. dp[(<<xx)].pre = ;
  65. xx++;
  66. if(xx == n) break;
  67. }
  68. for(int i = ;i < n; i++){
  69. scanf("%s %d %d", p[i].name, &p[i].D, &p[i].C);
  70. if(p[i].C > p[i].D)
  71. dp[<<i].w = p[i].C - p[i].D;
  72. else
  73. dp[<<i].w = ;
  74. }
  75. map <int, int> mp;
  76. for(int i = ; i < (<<n); i++){
  77. for(int j = ; j < n; j++){
  78. if(i&(<<j)){
  79. if(cal(i) > p[j].D){
  80. if(dp[i].w > dp[i^(<<j)].w + cal(i) - p[j].D){
  81. dp[i].w = dp[i^(<<j)].w + cal(i) - p[j].D;
  82. dp[i].pre = i^(<<j);
  83. mp[i] = i^(<<j);
  84. }
  85. else if(dp[i].w == dp[i^(<<j)].w + cal(i) - p[j].D && dp[i].pre > (i^(<<j))){
  86. dp[i].pre = i^(<<j);
  87. mp[i] = i^(<<j);
  88. }
  89. //dp[i] = min(dp[i], dp[i^(1<<j)] + cal(i) - p[j].D);
  90. }
  91. else{
  92. if(dp[i].w > dp[i^(<<j)].w){
  93. dp[i].w = dp[i^(<<j)].w;
  94. dp[i].pre = i^(<<j);
  95. mp[i] = i^(<<j);
  96. }
  97. else if(dp[i].w == dp[i^(<<j)].w && dp[i].pre > (i^(<<j))){
  98. dp[i].pre = i^(<<j);
  99. mp[i] = i^(<<j);
  100. }
  101. //dp[i] = min(dp[i], dp[i^(1<<j)]);
  102. }
  103. }
  104. }
  105. }
  106. printf("%d\n", dp[(<<n)-]);
  107. int now = (<<n) - ;
  108. ct = ;
  109. while(now){
  110. ans[ct++] = cal1(now, mp[now]);
  111. now = mp[now];
  112. }
  113. for(int i = n - ; i >= ; i--){
  114. printf("%s\n", p[ans[i]].name);
  115. }
  116. }
  117. return ;
  118. }

HDU 1074的更多相关文章

  1. 【状态DP】 HDU 1074 Doing Homework

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

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

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

  3. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

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

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

  5. HDU 1074 Doing Homework(状压DP)

    第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...

  6. hdu 1074 状态压缩

    http://acm.hdu.edu.cn/showproblem.php?pid=1074 我们可以断定状态的终止态一定是n个数全部选完的情况,那么它的前一个状态是什么呢,一定是剔除任一门课程后的n ...

  7. HDU 1074 Doing Homework【状态压缩DP】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意: 给定作业截止时间和完成作业所需时间,比截止时间晚一天扣一分,问如何安排作业的顺序使得最 ...

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

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

  9. HDU 1074 Doing Homework (状压dp)

    题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...

随机推荐

  1. Codeforces Round #308 (Div. 2)----C. Vanya and Scales

    C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. 项目三(集团官网)——总结(1) cookie

    最近十几天一直在忙着做集团官方网站的工作,从刚开始紧张的筹备一直到现在初步成型,今天才有时间特地来记录一下自己在这个项目中的收获. 先来说一说今天遇到的问题吧:关于cookie~ 事情起因是这样的:在 ...

  3. OpenLDAP使用疑惑解答及使用Java完成LDAP身份认证

    导读 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的数据库系统,其专门针对读取,浏览 ...

  4. Writing an Hadoop MapReduce Program in Python

    In this tutorial I will describe how to write a simpleMapReduce program for Hadoop in thePython prog ...

  5. HookSSDT 通过HookOpenProcess函数阻止暴力枚举进程

    首先要知道Ring3层调用OpenProcess的流程 //当Ring3调用OpenProcess //1从自己的模块(.exe)的导入表中取值 //2Ntdll.dll模块的导出表中执行ZwOpen ...

  6. js基础之DOM

    一.创建子节点 发帖在顶部显示: var oBtn = document.getElementById('btn1'); var oUl = document.getElementById('ul1' ...

  7. adMob iAd整合,随机根据网络状况自动显示。

    最近找整合的代码,找到的都不对,有个大概对的,但要奔溃退出,只要两个单独弄. adMob 下载好sdk,导入进去,iAd的加入iad framework. 使用方法,在viewController v ...

  8. 其他窗体赋值给comboBox实现值的回显,并使赋的值处于选中状态(根据text获取selectedindex)

    Form1 发货单位的这个下拉框comboBox1已经绑定数据库test表的name字段,里面有很多单位名称 比如有:甲公司.乙公司... 1.Form1的comboBox1首先绑定数据库的数据表te ...

  9. [开发笔记]-VS2012打开解决方案崩溃或点击项目崩溃

    下午在使用VS2012建立Service服务项目时,只要一切换到设计视图页面中,VS就崩溃重启,从网上找了一种方法来解决,测试可行.但导致该问题的原因未知. 解决方案: 步骤1:开始-->所有程 ...

  10. MSP430G2553之timerA产生PWM

    总结:选SMCLK(可以测出来)         若选ACLK,经示波器PWM时有时无 举例一: #include <MSP430G2553.h> #define CPU_F ((doub ...