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)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
随机推荐
- 支持SQL Server数据库又支持MongoDB数据库的数据访问设计
网站整体架构建议采用工厂模式 分别包括:数据访问层DAL,数据访问接口层IDAL,工厂层DALFactory,业务逻辑层,显示层这样的架构方式 在WebConfig配置采用何种数据库的数据访问层 &l ...
- CSS3学习教程:Media Queries详解
说起CSS3的新特性,就不得不提到 Media Queries . Media Queries 的引入,其作用就是允许添加表达式用以确定媒体的情况,以此来应用不同的样式表.换句话说,其允许我们在不改变 ...
- HDU 5773 The All-purpose Zero 求LIS
求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以 ...
- 时钟 IoTimer
/* 例程是在运行在DISPATCH_LEVEL的IRQL级别 例程中不能使用分页内存 另外在函数首部使用 #pragma LOCKEDCODE */ #include "Driver.h& ...
- [Jquery]瀑布流
$(window).load(function(e){ waterfall(); var dataInt={'data':[{'src':'1.jpg'},{'src':'2.jpg'}, ...
- Unity3d之MonoBehaviour的可重写函数整理
最近在学习Unity3d的知识.虽然有很多资料都有记录了,可是我为了以后自己复习的时候方便就记录下来吧!下面的这些函数在Unity3d程序开发中具有很重要的作用. Update 当MonoBehavi ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- C#Winform从页面获取数据,传入数据库
环境: 1.SQLite数据库新建数据表,设置相应的字段.(其他数据库形式都相似,using相应数据库的包即可) 2.页面有两个textBox:textBox1.textBox2, 3.一个保存按钮: ...
- routeProvider
In a previous post about testing I mentioned that route resolves can make authoring unit tests for a ...
- Hibernate中的一对一映射
1.需求 用户和身份证是一一对应的关系. 有两种对应方式: 用户id作为身份证表的外键,身份证号作为主键: 用户id作为身份证表的主键: 2.实体Bean设计 User: public class U ...