https://vjudge.net/contest/68966#problem/D

http://blog.csdn.net/u010489389/article/details/19218795

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=;
int n;
struct hmwk
{
char ch[maxn];
int d;
int c;
}p[]; struct DP
{
int time;
int reduced;
int fa;
}dp[(<<)]; char s[][]; void Init()
{
for(int i=;i<(<<);i++)
{
dp[i].fa=-;
dp[i].time=;
dp[i].reduced=INF;
}
dp[].reduced=; }
//按字典序增序输出
bool cmp(const hmwk&x,const hmwk& y)
{
return strcmp(x.ch,y.ch)<=;
}
//递归输出,x为当前,fa为前一个
void Print(int x,int fa)
{
int flag;
if(x==)
{
for(int i=;i<n;i++)
{
if(fa&(<<i))
{
flag=i;
break;
}
}
printf("%s\n",p[flag].ch);
return;
}
Print(dp[x].fa,x);
for(int i=;i<n;i++)
{
if((x&(<<i))!=(fa&(<<i)))
{
flag=i;
break;
}
}
if(x==)
{
printf("%s\n",p[flag].ch);
}
else
{
printf("%s\n",p[flag].ch);
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{ scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%s%d%d",p[i].ch,&p[i].d,&p[i].c);
}
sort(p,p+n,cmp);
Init();
//每个i代表一个状态,i的每一位代表一个科目
for(int i=;i<(<<n);i++)
{
for(int k=;k<n;k++)
{
//如果是1跳过
if(i&(<<k))
{
continue;
}
//now为转移后的状态
int now=i+(<<k);
dp[now].time=dp[i].time+p[k].c;
//dp[now].time-p[k].d<0说明没有延期,就是0
if(dp[i].reduced+max(,dp[now].time-p[k].d)<dp[now].reduced)
{
dp[now].reduced=dp[i].reduced+max(,dp[now].time-p[k].d);
dp[now].fa=i;
}
}
}
//最终结果就是111111(n个1),对应的数就是(1<<n)-1
printf("%d\n",dp[(<<n)-].reduced);
Print(dp[(<<n)-].fa,(<<n)-);
}
return ;
}

【算法系列学习】状压dp [kuangbin带你飞]专题十二 基础DP1 D - Doing Homework的更多相关文章

  1. 【算法系列学习】DP和滚动数组 [kuangbin带你飞]专题十二 基础DP1 A - Max Sum Plus Plus

    A - Max Sum Plus Plus https://vjudge.net/contest/68966#problem/A http://www.cnblogs.com/kuangbin/arc ...

  2. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 C - Monkey and Banana

    https://vjudge.net/contest/68966#problem/C [参考]http://blog.csdn.net/qinmusiyan/article/details/79862 ...

  3. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 G - 免费馅饼

    https://vjudge.net/contest/68966#problem/G 正解一: http://www.clanfei.com/2012/04/646.html #include< ...

  4. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 F - Piggy-Bank 【完全背包问题】

    https://vjudge.net/contest/68966#problem/F http://blog.csdn.net/libin56842/article/details/9048173 # ...

  5. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 E - Super Jumping! Jumping! Jumping!

    https://vjudge.net/contest/68966#problem/E http://blog.csdn.net/to_be_better/article/details/5056334 ...

  6. 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV

    http://www.cnblogs.com/joeylee97/p/6616039.html 引入一个cnt,输入元素与上一个元素相同,cnt增加,否则cnt减少,当cnt为零时记录输入元素,因为所 ...

  7. [kuangbin带你飞]专题十二 基础DP1

            ID Origin Title   167 / 465 Problem A HDU 1024 Max Sum Plus Plus   234 / 372 Problem B HDU 1 ...

  8. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题十二 HDU 1176 免费馅饼

    题意: 中文题意不解释…… 思路: 先把x,T存到矩阵里 然后像数塔一样从最底层走一边就行了 dp[i][j]代表在时间为j时 第i个位置最多能吃到多少个馅饼 最后输出第0时刻的5位置的馅饼数量就好了 ...

  9. [kuangbin带你飞]专题十五 数位DP

            ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HD ...

随机推荐

  1. linux 私房菜 CH5 笔记

    知识点 linux 大小写敏感 接口的切换 [Ctrl] + [Alt] + [F1] ~ [F6] :文字接口登入 tty1 ~ tty6 终端机: [Ctrl] + [Alt] + [F7] :图 ...

  2. python IP地址转16进制

    python IP地址转16进制 第一种方法: 通过socket.inet_aton实现 import socket from binascii import hexlify ary='192.168 ...

  3. 用python抓取求职网站信息

    本次抓取的是智联招聘网站搜索“数据分析师”之后的信息. python版本: python3.5. 我用的主要package是 Beautifulsoup + Requests+csv 另外,我将招聘内 ...

  4. STM32F103RC进入串口3接收中断产生HardFault_Hander问题解决!

    最近在以前的项目上添加串口3通讯后,程序一进入接收中断后就产生HardFault_Hander.串口3发送数据一切正常,当打开串口3接收功能时,程序就处于HardFault_Hander状态,而导致死 ...

  5. TIME_WAIT 另一种解决方式 SO_LINGER

         被TIME_WAIT问题烦得不行,又发现了另一种解决方式,SO_LINGER.      对SO_LINGER解释最通用的自然是<UNP>,现摘录如下      SO_LINGE ...

  6. XML配置文件的命名空间与Spring配置文件中的头

    一直以来,写Spring配置文件,都是把其他配置文件的头拷贝过来,最多改改版本号,也不清楚哪些是需要的,到底是干嘛的.今天整理一下,拒绝再无脑copy. 一.Spring配置文件常见的配置头 < ...

  7. Java的标识符,数据类型与各种运算符

    一.标识符 用作给变量.类和方法命名 java强调标识符有如下命名规则: 标识符必须以字母,下划线_,美元$开头 标识符其他部分可以是字母,下划线"_",美元符"$&qu ...

  8. Spring execution表达式

    execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) th ...

  9. 老李推荐:第14章6节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-启动ViewServer

    老李推荐:第14章6节<MonkeyRunner源码剖析> HierarchyViewer实现原理-装备ViewServer-启动ViewServer   poptest是国内唯一一家培养 ...

  10. 老李分享:android手机测试之适配(1)

    Android的屏幕适配一直以来都在折磨着我们这些开发者,本篇文章以Google的官方文档为基础,全面而深入的讲解了Android屏幕适配的原因.重要概念.解决方案及最佳实践,我相信如果你能认真的学习 ...