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)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
随机推荐
- Java 之 I/O 系列 02 ——序列化(二)
Java 之 I/O 系列 目录 Java 之 I/O 系列 01 ——基础 Java 之 I/O 系列 02 ——序列化(一) Java 之 I/O 系列 02 ——序列化(二) 继续上篇的第二个问 ...
- word linkage 选择合适的聚类个数matlab code
clear load fisheriris X = meas; m = size(X,2); % load machine % load census % % X = meas; % X=X(1:20 ...
- 一些git命令
git push --set-upstream origin release 强制将add的数据提交到 release分支.
- BZOJ1962 模型王子
戳这里 /************************************************************** Problem: 1962 User: rausen Langu ...
- was7 安装遇到问题(Linux平台Redhat 6)
1../launchpad.sh 无法启动安装,提示无法找到浏览器 解决:直接进入WAS文件夹,执行install cd WAS ./install 2.安装时中文乱码 设置区域为美国: LANG=e ...
- [Hadoop入门] - 2 ubuntu安装与配置 hadoop安装与配置
ubuntu安装(这里我就不一一捉图了,只引用一个网址, 相信大家能力) ubuntu安装参考教程: http://jingyan.baidu.com/article/14bd256e0ca52eb ...
- 文本信息“welcome to java programming!”
import javax.swing.JOptionPanepublic class welcome {public static void main(string[] arg){JOptionPan ...
- "QQ尾巴病毒"核心技术的实现原理分析
声明:本文旨在探讨技术,请读者不要使用文章中的方法进行任何破坏. 2003这一年里,QQ尾巴病毒可以算是风光了一阵子.它利用IE的邮件头漏洞在QQ上疯狂传播.中毒者在给别人发信息时,病毒会自动在信息文 ...
- visual studio 2013连接Oracle 11g并获取数据:(一:环境搭建)
C# WinForm案例: 目标: visual studio 中点击按钮,就可获取到Oracle中数据表的内容 1.安装Visual Studio 2013 ,推荐如下网址,下载ISO镜像,一路ne ...
- Convert.ToInt16 与 Convert.ToInt32 区别
取值的范围不同: int16:-32768 到 32767 int32:-2,147,483,648 到 2,147,483,647