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

Doing Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12269    Accepted Submission(s): 5911

Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test, 1 day for 1 point. And as you know, doing homework always takes a long time. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
 
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=15) which indicate the number of homework. Then N lines follow. Each line contains a string S(the subject's name, each string will at most has 100 characters) and two integers D(the deadline of the subject), C(how many days will it take Ignatius to finish this subject's homework).

Note: All the subject names are given in the alphabet increasing order. So you may process the problem much easier.

 
Output
For each test case, you should output the smallest total reduced score, then give out the order of the subjects, one subject in a line. If there are more than one orders, you should output the alphabet smallest one.
 
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

Hint

In the second test case, both Computer->English->Math and Computer->Math->English leads to reduce 3 points, but the
word "English" appears earlier than the word "Math", so we choose the first order. That is so-called alphabet order.

 
 
题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限。超期多少天就要扣多少分。问最少被扣多少分,且按字典序输出做作业顺序。
题解:由于N<=15,所以可以想到使用状压DP。
特别地,此类DP问题,需要满足同级的进行递推的顺序不影响结果,比如状态 5 (101)与6(110)的顺序无关紧要,因为不是由它推过来的,所以这道题可以使用状压DP(如果5与6出现的顺序影响结果的话就不能使用状压DP了)
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct sta {
char ss[];
int tim;
int del;
}st[],skt[<<];
int dp[ << ];
int pre[ << ];
void print(int x,int y) {
if (x == ) {
return;
}
print(x-(<<y), pre[x-(<<y)]);
printf("%s\n",st[y].ss);
}
int main() {
int t;
scanf("%d",&t);
while (t--) {
int n;
scanf("%d",&n);
for (int i = ; i < n; i++) {
scanf("%s%d%d",st[i].ss,&st[i].del,&st[i].tim);
}
memset(dp, 0x3f3f3f3f, sizeof(dp));
dp[] = ;
skt[].tim = ;
for (int i = ; i < ( << n); i++) {
for (int j = n - ; j >= ; j--) {
if (( << j)&i) {
int cost = skt[i - ( << j)].tim + st[j].tim - st[j].del;
if (cost < )cost = ;
if (cost + dp[i-(<<j)] < dp[i]) {
dp[i] = cost + dp[i - ( << j)];
skt[i].tim = skt[i - ( << j)].tim + st[j].tim;
pre[i] = j;
}
}
}
}
cout << dp[( << n) - ] << endl;
print((<<n)-,pre[(<<n)-]);
}
return ;
}
 

【状压DP】【HDOJ1074】的更多相关文章

  1. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  2. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  3. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  4. [NOIP2016]愤怒的小鸟 D2 T3 状压DP

    [NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...

  5. 【BZOJ2073】[POI2004]PRZ 状压DP

    [BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...

  6. bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)

    数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...

  7. HDU 1074 Doing Homework (状压dp)

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

  8. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  9. 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP

    [BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...

随机推荐

  1. python vue 项目

    http://www.jianshu.com/p/fe74907e16b9 mac 电脑,亲测可以,可以看下开源的写法及思路

  2. day20-正则表达式练习

    import re from re import findall,search,S secret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdf ...

  3. python全栈开发笔记---------变量小结

    变量是什么? 变:变化,重在变字,量:计量,衡量,表示一种状态. 变量字面理解就是一个可能改变的量,也就是这个值是不固定的. 变量名: a.数字 b.字母 c.下划线 变量的定义 level = 1 ...

  4. 【转载】ZooKeeper学习第二期--ZooKeeper安装配置

    原文地址(https://www.cnblogs.com/sunddenly/p/4018459.html) 一.Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及 ...

  5. java的类class 和对象object

    java 语言的源代码是以类为单位存放在文件中,已public修饰的类名须和存放这个类的源文件名一样.而 一个源文件中只能有一个public的类,类名的首字母通常为大写. 使用public修饰的类可以 ...

  6. 如何使用VSTO自动将Excel中的图表复制到Word

    如何使用VSTO自动将Excel中的图表复制到Word 原文地址:https://code.msdn.microsoft.com/How-to-copy-Chart-in-Excel-a29f9029 ...

  7. 4.5 C++重载、覆盖和遮蔽

    参考:http://www.weixueyuan.net/view/6375.html 总结: 函数签名包括函数名和函数参数的个数.顺序以及参数数据类型. 需要注意的是函数签名并不包含函数返回值部分, ...

  8. jQuery $.each()常见的几种使用方法

    <code class="language-html"><!doctype html> <html> <head> <meta ...

  9. Zabbix4.0监控URL

    一:新建群组 1.1:web monitor 二:新建模板 2.1:配置-模板-模板 2.3:创建应用集 配置-模板-web monitor-应用集 2.4:创建web场景 2.5:创建场景步骤: 以 ...

  10. UI控件Telerik UI for WinForms发布R1 2019|附下载

    Telerik UI for WinForms拥有适用Windows Forms的110多个令人惊叹的UI控件.所有的UI for WinForms控件都具有完整的主题支持,可以轻松地帮助开发人员在桌 ...