HDU 1074
http://acm.hdu.edu.cn/showproblem.php?pid=1074
每个任务有一个截止日期和完成时间,超过截止日期一天扣一分,问完成全部任务最少扣几分,并输出路径
最多15个任务,状态压缩一下进行dp,输出路径的话要记录每种状态的前驱,存起来逆序输出
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std; const int INF = 0xfffffff; struct fuck{
int w, pre;
}dp[<<]; struct node{
char name[];
int D, C;
}p[]; int cal(int x){
int res = , cnt = ;
while(x){
if(x & ){
res += p[cnt].C;
}
cnt++;
x >>= ;
}
return res;
} int cnt(int x){
int res = ;
while(x){
if(x & ){
res++;
}
x >>= ;
}
return res;
} int cal1(int x, int y){
int res = ;
while(){
if((x&) != (y&)){
return res;
}
res++;
x >>= ; y >>= ;
}
} int ans[], ct; int main(){
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
for(int i = ; i < (<<n); i++)
dp[i].w = INF;
int xx = ;
while(){
dp[(<<xx)].pre = ;
xx++;
if(xx == n) break;
}
for(int i = ;i < n; i++){
scanf("%s %d %d", p[i].name, &p[i].D, &p[i].C);
if(p[i].C > p[i].D)
dp[<<i].w = p[i].C - p[i].D;
else
dp[<<i].w = ;
}
map <int, int> mp;
for(int i = ; i < (<<n); i++){
for(int j = ; j < n; j++){
if(i&(<<j)){
if(cal(i) > p[j].D){
if(dp[i].w > dp[i^(<<j)].w + cal(i) - p[j].D){
dp[i].w = dp[i^(<<j)].w + cal(i) - p[j].D;
dp[i].pre = i^(<<j);
mp[i] = i^(<<j);
}
else if(dp[i].w == dp[i^(<<j)].w + cal(i) - p[j].D && dp[i].pre > (i^(<<j))){
dp[i].pre = i^(<<j);
mp[i] = i^(<<j);
}
//dp[i] = min(dp[i], dp[i^(1<<j)] + cal(i) - p[j].D);
}
else{
if(dp[i].w > dp[i^(<<j)].w){
dp[i].w = dp[i^(<<j)].w;
dp[i].pre = i^(<<j);
mp[i] = i^(<<j);
}
else if(dp[i].w == dp[i^(<<j)].w && dp[i].pre > (i^(<<j))){
dp[i].pre = i^(<<j);
mp[i] = i^(<<j);
}
//dp[i] = min(dp[i], dp[i^(1<<j)]);
}
}
}
}
printf("%d\n", dp[(<<n)-]);
int now = (<<n) - ;
ct = ;
while(now){
ans[ct++] = cal1(now, mp[now]);
now = mp[now];
}
for(int i = n - ; i >= ; i--){
printf("%s\n", p[ans[i]].name);
}
}
return ;
}
HDU 1074的更多相关文章
- 【状态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 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- hdu 1074 状态压缩
http://acm.hdu.edu.cn/showproblem.php?pid=1074 我们可以断定状态的终止态一定是n个数全部选完的情况,那么它的前一个状态是什么呢,一定是剔除任一门课程后的n ...
- 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)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
随机推荐
- [示例]NSDictionary编程题-字典的排序应用(iOS5班)
代码? #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepo ...
- oracle查询语句大全
1.查处oracle数据库的字符编码格式 select * from v$nls_parameters t where t.PARAMETER='NLS_CHARACTERSET'; 如果查出的是ZH ...
- bzoj 2037: [Sdoi2008]Sue的小球
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; struc ...
- bzoj 1816: [Cqoi2010]扑克牌
#include<cstdio> #include<iostream> using namespace std; ],ans; bool pan(int x) { int a1 ...
- CodeForces 441E(Codeforces Round #252 (Div. 2))
思路:dp[i][now][mark][len] i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等. 只存后8位的原因:操作只有200次 ...
- PowerMock使用遇到的问题——1
遇到问题:再用PowerMock Mock构造方法时,所有语句都可以通过执行,但当最后执行verify语句时却总是出现如下错误: java.lang.AssertionError: ...
- C语言中文件的读取和写入
在C语言中写文件 //获取文件指针 FILE *pFile = fopen("1.txt", //打开文件的名称 "w"); // 文件打开方式 如果原来有内容 ...
- HTTP协议的chunked编码
一般情况HTTP的Header包含Content-Length域来指明报文体的长度.如: 有时候服务生成HTTP回应是无法确定消息大小的,比如大文件的下载,或者后台需要复杂的逻辑才能全部处理页面的请求 ...
- HMM TOOL
HMM隐马尔科夫模型 MATLAB 工具包对各种数据的处理 HMM 工具包下载地址: http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html 工具包使用 ...
- 屏蔽Win10升级通知方法
对于有系统洁癖的我来说,不喜欢还原和自动升级,我更乐意使用全新安装的方式来装系统! 据说微软也知道这种方式有时候的确很讨人嫌,因此就低调的在美国微软社区中给出了屏蔽这项通知的官方"大法&qu ...