由于数据量较小,直接二进制模拟全排列过程,进行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. Ext.Ajax.request()方法和FormPanel.getForm().submit()方法,都返回success()方法的差异

    我还是不发表到博客园首页吧,要不然还是要被取消,>_< 还是言归正传吧,关于Ext.Ajax.request()方法和FormPanel.getForm().submit()方法返回suc ...

  2. Python读写文件 - 转

    http://blog.csdn.net/adupt/article/details/4435615 http://docs.python.org/release/2.5.2/lib/bltin-fi ...

  3. Chp3: Stacks and Queue

    1. 说明如何用两个队列来实现一个栈,并分析有关栈操作的运行时间. 解法:1.有两个队列q1和q2,先往q1内插入a,b,c,这做的都是栈的push操作.2.现在要做pop操作,即要得到c,这时可以将 ...

  4. strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签

    定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...

  5. Zookeeper + Hadoop + Hbase部署备忘

    网上类似的文章很多,本文只是记录下来备忘.本文分四大步骤: 准备工作.安装zookeeper.安装hadoop.安装hbase,下面分别详细介绍: 一 准备工作 1. 下载 zookeeper.had ...

  6. 使用SpringAop 验证方法参数是否合法

    (原文地址:http://blog.csdn.net/is_zhoufeng/article/details/7683194) 1.依赖包    aspectjweaver.jar 其中Maven的配 ...

  7. SPRING IN ACTION 第4版笔记-第九章Securing web applications-001-SpringSecurity简介(DelegatingFilterProxy、AbstractSecurityWebApplicationInitializer、WebSecurityConfigurerAdapter、@EnableWebSecurity、@EnableWebMvcS)

    一.SpringSecurity的模块 At the least, you’ll want to include the Core and Configuration modules in your ...

  8. 每个QWidget都有contentsMargins函数,善用QMargins

    m_pSearchLineEdit = new QLineEdit(); QPushButton *pSearchButton = new QPushButton(this); pSearchButt ...

  9. IIS8报错 403 404

    当IIS报403错误,而打开目录浏览权限后,又出404错误,这种错误很可能是.net的版本安装问题 注意勾选上asp.net4.5

  10. NFC(10)NDEF uri格式规范及读写示例(解析与封装ndef uri)

    只有遵守NDEF uri 格式规范的数据才能写到nfc标签上. NDEF uri 格式规范 uri 只有两部分: 第1个字节是uri协议映射值,如:0x01 表示uri以 http://www.开头. ...