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)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
随机推荐
- 在Handler.ashx文件中使用session
使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session.按照以下步骤,即可以通过session与其他的aspx页面的session进行数 ...
- python——使用readline库实现tab自动补全
Input History readline tracks the input history automatically. There are two different sets of funct ...
- [转]无IDE时编译和运行Java
本文由 ImportNew - Grey 翻译自 dzone.欢迎加入Java小组.转载请参见文章末尾的要求. 最近 Java subreddit 出现了一篇”在没有IDE的情况下编译Java包” 的 ...
- [转]C#中的Monitor类
object obj=new object(); Monitor在锁对象obj上会维持两个线程队列R和W以及一个引用T : (1) T是对当前获得了obj锁的线程的引用(设此线程为CurrThread ...
- gitlab配置邮件通知
配置用户提交评论.添加issue等的邮件通知: Gitlab邮件提醒方便跟踪项目进度,在这里介绍两种方式,一种是用系统的sendmail发送邮件,另一种是GMAIL的stmp来发送邮件 第一种 用系统 ...
- HtmlAgilityPack解析全国区号页面到XML
需求:完成一个城市和区号的xml配置文件 处理思路:通过HtmlAgilityPack解析一个区号页面,生产xml文件 页面:http://www.hljboli.gov.cn/html/code.h ...
- iOS 登陆的实现四种方式
iOS 登陆的实现四种方式 一. 网页加载: http://www.cnblogs.com/tekkaman/archive/2013/02/21/2920218.ht ml [iOS登陆的实现] A ...
- POJ 3299 Humidex 难度:0
题目链接:http://poj.org/problem?id=3299 #include <iostream> #include <iomanip> using namespa ...
- 设置groupBox背景透明
步骤:属性-BackColor-WEB面板-Transparent
- IT公司100题-11-求二叉树中节点的最大距离
问题描述: 写程序,求一棵二叉树中相距最远的两个节点之间的距离. 10/ \6 14/ \ / \4 8 12 16 分析: 二叉树中最远的两个节点,要么是根 ...