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)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
随机推荐
- Codeforces Round #308 (Div. 2)----C. Vanya and Scales
C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 项目三(集团官网)——总结(1) cookie
最近十几天一直在忙着做集团官方网站的工作,从刚开始紧张的筹备一直到现在初步成型,今天才有时间特地来记录一下自己在这个项目中的收获. 先来说一说今天遇到的问题吧:关于cookie~ 事情起因是这样的:在 ...
- OpenLDAP使用疑惑解答及使用Java完成LDAP身份认证
导读 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的数据库系统,其专门针对读取,浏览 ...
- Writing an Hadoop MapReduce Program in Python
In this tutorial I will describe how to write a simpleMapReduce program for Hadoop in thePython prog ...
- HookSSDT 通过HookOpenProcess函数阻止暴力枚举进程
首先要知道Ring3层调用OpenProcess的流程 //当Ring3调用OpenProcess //1从自己的模块(.exe)的导入表中取值 //2Ntdll.dll模块的导出表中执行ZwOpen ...
- js基础之DOM
一.创建子节点 发帖在顶部显示: var oBtn = document.getElementById('btn1'); var oUl = document.getElementById('ul1' ...
- adMob iAd整合,随机根据网络状况自动显示。
最近找整合的代码,找到的都不对,有个大概对的,但要奔溃退出,只要两个单独弄. adMob 下载好sdk,导入进去,iAd的加入iad framework. 使用方法,在viewController v ...
- 其他窗体赋值给comboBox实现值的回显,并使赋的值处于选中状态(根据text获取selectedindex)
Form1 发货单位的这个下拉框comboBox1已经绑定数据库test表的name字段,里面有很多单位名称 比如有:甲公司.乙公司... 1.Form1的comboBox1首先绑定数据库的数据表te ...
- [开发笔记]-VS2012打开解决方案崩溃或点击项目崩溃
下午在使用VS2012建立Service服务项目时,只要一切换到设计视图页面中,VS就崩溃重启,从网上找了一种方法来解决,测试可行.但导致该问题的原因未知. 解决方案: 步骤1:开始-->所有程 ...
- MSP430G2553之timerA产生PWM
总结:选SMCLK(可以测出来) 若选ACLK,经示波器PWM时有时无 举例一: #include <MSP430G2553.h> #define CPU_F ((doub ...