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. 逆袭之旅DAY17.东软实训.Oracle.PLSQL.过程,函数,包,练习

    2018-07-13 14:54:46 --1.创建一个包,包含一个为雇员加薪的过程,一个为雇员减薪的过程 CREATE OR REPLACE PACKAGE pac_test1 IS PROCEDU ...

  2. Mysql 行存储的文件格式

    一.Mysql行存储的文件格式概述 InnoDB存储引擎有两种文件格式 Antelope:compact与redundant两种行记录格式 Barracuda:compress与dynamic两种行记 ...

  3. MySQL字符集与校对

    一.什么是字符集与校对 1.字符集与校对 字符集是指一种从二进制编码到某种字符符号的映射. 校队是指一组用于某个字符集的配许规则. 2.utf8与utf8mb4 标准的UTF-8字符集编码是可以使用1 ...

  4. Saiku连接mysql数据库(二)

    Saiku连接Mysql数据库展示数据 参考链接:https://www.cnblogs.com/shirui/p/8573491.html 官方文档:https://media.readthedoc ...

  5. caffe的一些概念理解

    有一天,师姐问我,epoch和iteration有什么区别?我一时语塞,竟然遍寻百度而不得,最后在stackoverflow上找到一个我认为比较靠谱的答案,虽然它不是最高票,但是是最好理解的,深得我心 ...

  6. JNA调用DLL(入门):让你一眼就学会

    DLL(Dynamic Link Library)文件,是基于C语言的动态链接库文件,就是一些封装好的方法,打成dll格式包,供别人调用 JNA是一种能够使Java语言使调用DLL的一种技术, 首先, ...

  7. Android : android 8.0 audio 接口分析

    1.HIDL 的概念 HIDL 读作 hide-l,全称是 Hardware Interface Definition Language.它在 Android Project Treble 中被起草, ...

  8. Final发布

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2476] 文案+美工[https://www.cnblogs.com/erciy ...

  9. 六、在U-boot中让LCD填充纯色

    1. 编译U-boot 准备好U-boot压缩包urbetter-u-boot-1.1.6-v1.0.tgz,输入命令:tar -xvf urbetter-u-boot-1.1.6-v1.0.tgz ...

  10. NodeJs -- URL 模块.

    1. url.parse(网址): 将字符串 解析成对象.  1-1) 一个参数 : 或者  参数1, false(默认), false(默认) var url = require('url'); c ...