Doing Homework HDU - 1074
InputThe 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.
OutputFor 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.
第一个DP状态压缩的题,看了好久。希望下次做的时候可以懂一点点吧。
// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#define INF 0x3f3f3f3f
#define mod 2016
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = (<<)+;
int n, m, T, len, cnt, num, ans, Max;
int dp[maxn], t[maxn], pre[maxn], d[], f[];
char str[][]; void output(int x) {
if( !x ) return ;
output(x-(<<pre[x]));
printf("%s\n", str[pre[x]]);
} void input() {
scanf("%d", &T);
while( T -- ) {
scanf("%d", &n);
for(int i=; i<n; i++) scanf("%s%d%d",str[i], &d[i], &f[i]);
int bit = << n;
for(int i=; i<=bit; i++) {
dp[i] = INF;
for(int j=n-; j>=; j--) {
int te = <<j;
if( !(i&te) ) continue;
int sc = t[i-te]+f[j]-d[j];
if( sc< ) sc = ;
if( dp[i]>dp[i-te]+sc) {
dp[i] = dp[i-te]+sc;
t[i] = t[i-te]+f[j];
pre[i] = j;
}
}
}
printf("%d\n", dp[bit-]);
output(bit-);
}
} int main() {
input();
return ;
}
感谢大神http://blog.csdn.net/xingyeyongheng/article/details/21742341
Doing Homework HDU - 1074的更多相关文章
- 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 ...
- D - Doing Homework HDU - 1074 (状压dp)
题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求 10 ...
- Doing Homework HDU - 1074 状态压缩
#include<iostream> #include<cstring> #include<cstdio> #include<string> #incl ...
- Day9 - G - Doing Homework HDU - 1074
有n个任务,每个任务有一个截止时间,超过截止时间一天,要扣一个分.求如何安排任务,使得扣的分数最少.Input有多组测试数据.第一行一个整数表示测试数据的组数第一行一个整数n(1<=n<= ...
- 【状态DP】 HDU 1074 Doing Homework
原题直通车:HDU 1074 Doing Homework 题意:有n门功课需要完成,每一门功课都有时间期限t.完成需要的时间d,如果完成的时间走出时间限制,就会被减 (d-t)个学分.问:按怎样 ...
- HDU 1074 Doing Homework (动态规划,位运算)
HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
- HDU 1074:Doing Homework(状压DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Problem Description Ignatius has just ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
随机推荐
- SLAM最近的工作
- css实现右侧固定宽度,左侧宽度自适应
https://blog.csdn.net/qq_22889599/article/details/78414040 反过来也可以:左侧宽度固定,右侧自适应.不管是左是右,反正就是一边宽度固定,一边宽 ...
- [LeetCode] 492. Construct the Rectangle_Easy tag: Math
For a web developer, it is very important to know how to design a web page's size. So, given a speci ...
- js图的数据结构处理---迪杰斯特拉算法
/*//1.确定数据结构, mapf[i][j] 为点i到点j的距离 [ Infinity 2 5 Infinity Infinity Infinity Infinity 2 6 Infinity I ...
- js图的数据结构处理----邻链表,广度优先搜索,最小路径,深度优先搜索,探索时间拓扑
//邻居连表 //先加入各顶点,然后加入边 //队列 var Queue = (function(){ var item = new WeakMap(); class Queue{ construct ...
- Amazon RDS 上的 Microsoft SQL Server » 导入和导出 SQL Server 数据库
导入和导出 SQL Server 数据库 Amazon RDS 支持使用完整备份文件 (.bak 文件) 对 Microsoft SQL Server 数据库进行本机备份和还原.您可以在单个便携式文件 ...
- Node.js进击基础一(http)
URL:统一资源定位符,偏重定位,是URI的子集,例如网址.URL一定是URI,但URI 不一定是URL.规则:只能用英文阿拉伯数字某些符号等,如果有文字就必须编码. URI:统一资源标识符,偏重标识 ...
- 家庭记账本之微信小程序(一)
记得ppt中说到,可以制作为微信小程序或者是安卓的应用,但是在我了解后觉得小应用有点力不从心,所以还是从微信小程序开始吧,先让我们了解一下主要的东西 1.准备工作 IDE搭建2.知识准备从零开始app ...
- Selenium基础知识(四)表单切换
在测试过程中,经常会碰到frame和iframe,嵌套等情况 这种情况下直接通过id,name等等是无法定位到的 好在selenium替我们想到了这个问题switch_to方法解决问题 switch_ ...
- “无效数字” ;java.lang.Integer cannot be cast to java.lang.String
今天页面上突然查询不出数据,大致的sql语句是 select xx ,xxx from table a where a.lrmb in ( 6101060033, 61010503300, 61016 ...