由于数据量较小,直接二进制模拟全排列过程,进行DP,思路由kuangbin blog得到,膜拜斌神

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
struct asd
{
char name[];
int deadline,cost;
} o[];
struct cc
{
int pre;
int cost;
int reduced;
} dp[<<];
bool vis[<<];
int tt;
void output(int now)
{
int cur=(dp[now].pre^now);
cur>>=;
int c=;
while(cur)
{
++c;
cur>>=;
}
if(dp[now].pre!=)
output(dp[now].pre);
printf("%s\n",o[c].name);
}
int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=; i<n; ++i)
scanf("%s%d%d",o[i].name,&o[i].deadline,&o[i].cost);
dp[].cost=;
dp[].reduced=;
dp[].pre=-;
memset(vis,,sizeof(vis));
vis[]=;
tt=(<<n)-;
for(int i=; i<tt; ++i)
{
for(int j=; j<n; ++j)
{ if((i&(<<j))==)
{
int cur=(i|(<<j));
if(vis[cur])
{
int more=dp[cur].cost-o[j].deadline;
more=max(,more)+dp[i].reduced;
if(more<dp[cur].reduced)
dp[cur].pre=i,dp[cur].reduced=more; }
else
{
dp[cur].pre=i;
dp[cur].cost=dp[i].cost+o[j].cost;
int more=dp[cur].cost-o[j].deadline;
dp[cur].reduced=dp[i].reduced+max(more,);
vis[cur]=;
}
}
}
}
printf("%d\n",dp[tt].reduced);
output(tt);
}
return

HDU 1074 Doing Homework 状压DP的更多相关文章

  1. HDU 1074 Doing Homework 状压dp(第一道入门题)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. HDU 1074 Doing Homework (状压DP)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  4. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. hdu_1074_Doing Homework(状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意:给你n个课程(n<=15)每个课程有限制的期限和完成该课程的时间,如果超出时间,每超 ...

  6. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  7. HDU 1074 Doing Homework(像缩进DP)

    Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...

  8. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  9. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

随机推荐

  1. resin access.log format配置详解

    The access log formatting variables follow the Apache variables:     %b result content length %D tim ...

  2. 1074: [SCOI2007]折纸origami - BZOJ

    Description 桌上有一张边界平行于坐标轴的正方形纸片,左下角的坐标为(0,0),右上角的坐标为(100,100).接下来执行n条折纸命令.每条命令用两个不同点P1(x1,y1)和P2(x2, ...

  3. 写给 iOS 开发者的 Hopper + lldb 简介

    最近,关于 @Steipete 在Radar发布的帖子,笔者看到很多人在问「你是怎么理解那个伪代码的」.笔者想写博客已经有一段时间了,现在正好就此发表第一篇博文.笔者在一个叫 Hopper 的工具上花 ...

  4. Android studio 下的 NDK 配置方法和注意事项

    http://blog.csdn.net/u013598660/article/details/47341963

  5. gdb调试多线程程序总结

    阿里核心系统团队博客 http://csrd.aliapp.com/?tag=pstack Linux下多线程查看工具(pstree.ps.pstack) http://www.cnblogs.com ...

  6. Servlet课程0425(六) 不经过验证直接跳转---session实现不同页面之间共享数据

    在地址栏直接输入http://localhost:8080/myWebSite/wel 会发现页面也能跳转,只不过用户名和密码都为空,这是不可以的,因为没有经过验证非法登录了 Welcome,hell ...

  7. Web开发的绝美网站

    http://paranimage.com/ http://sixrevisions.com/graphics-design/

  8. Android:布局合集

    本文归纳Android布局中所用到的知识点,网络上的教程说得太细化,而对于前端来说,下面的归纳最适合不过了. Android五大布局: LinearLayout 线性布局 Relativelayout ...

  9. POJ 2255 Tree Recovery 二叉树的遍历

    前序和中序输入二叉树,后序输出二叉树:核心思想只有一个,前序的每个根都把中序分成了两部分,例如 DBACEGF ABCDEFG D把中序遍历的结果分成了ABC和EFG两部分,实际上,这就是D这个根的左 ...

  10. Retrofit初识

    Retrofit Retrofit是一套RESTful架构的Android(Java)客户端实现,基于注解,提供JSON to POJO(Plain Ordinary Java Object,简单Ja ...