HDU1074(状态压缩DP)
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7070 Accepted Submission(s): 3104
Each test case start with a positive integer N(1<=N<=15) which indicate the number of homework. Then N lines follow. Each line contains a string S(the subject's name, each string will at most has 100 characters) and two integers D(the deadline of the subject), C(how many days will it take Ignatius to finish this subject's homework).
Note: All the subject names are given in the alphabet increasing order. So you may process the problem much easier.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=;
const int INF=0x3fffffff;
struct Node{
char s[];
int time,cost;
Node()
{
memset(s,,sizeof(s));
}
}a[MAXN];
int n;
int dp[<<MAXN];
int pre[<<MAXN];
void OutPut(int status)
{
if(status==)
return ;
int t=;
for(int i=;i<n;i++)
if((status&(<<i))!=&&(pre[status]&(<<i))==)
{
t=i;
break;
}
OutPut(pre[status]);
printf("%s\n",a[t].s);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%s",a[i].s);
scanf("%d%d",&a[i].time,&a[i].cost);
}
for(int i=;i<(<<MAXN);i++)
dp[i]=INF;
memset(pre,,sizeof(pre));
dp[]=;
for(int st=;st<(<<n);st++)
{
int w=;
for(int i=;i<n;i++)
{
if(st&(<<i))
w+=a[i].cost;
} for(int i=;i<n;i++)
{
if((st&(<<i))==)
{
if(dp[st|(<<i)]>dp[st]+max(,w+a[i].cost-a[i].time))
{
dp[st|(<<i)]=dp[st]+max(,w+a[i].cost-a[i].time);
pre[st|(<<i)]=st;
}
}
}
}
printf("%d\n",dp[(<<n)-]);
OutPut((<<n)-);
} return ;
}
HDU1074(状态压缩DP)的更多相关文章
- hdu1074 状态压缩dp+记录方案
题意: 给你一些作业,每个作业有自己的结束时间和花费时间,如果超过结束时间完成,一天扣一分,问你把n个作业完成最少的扣分,要求输出方案. 思路: 状态压缩dp,记录方案数的地方 ...
- HDU1074(KB12-D 状态压缩dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
随机推荐
- 翻翻git之---有用的欢迎页开源库 AppIntro
转载请注明出处:王亟亟的大牛之路 今天没有P1.直接进入正题 今天上的是一个帅帅的app滑动介绍页 . 为什么说帅? 作者对自己的内容是这么定义的 Make a cool intro for your ...
- C++获取站点的ip地址
#include "stdafx.h" #include <winsock2.h> #pragma comment (lib,"ws2_32.lib&q ...
- vs2012编译ffmpeg
从官方网站down下来的ffmpeg没有pdb文件不方便调试,为此使用VS2012编译ffmpeg. 编译步骤: 一.安装MinGW,具体的安装方法上一篇文章已经有介绍这里不在赘述. 二.下载文件并放 ...
- 封装PDO操作数据库
<?php class DatabaseHandler { /** * sql语句查询 */ public static function query_data ($dataName,$sql, ...
- kubernetes之常见故障排除(一)
系列目录 由由种种原因,在安装或者使用kubernetes的过程中,可能会遇到各种各样的问题.本篇按照官网的介绍罗列出一些常见的故障,以帮助快速解决一些常见的错误. 安装赛程中出现ebtables o ...
- caffe搭建--opensuse13.2上搭建caffe开发环境
第一部分:参考一下内容.将sudo 替换成zypper即可. --------------------------------------------这部分参照以下官网内容-------------- ...
- 改动UITextfield的Placeholder字体的颜色
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- java 重定向和转发(转载)
jsp中result的默认类型为dispatcher. dispatcher:与<jsp:forward page=""/>效果相同 redirect:与respons ...
- Jquery源码分析-整体结构
最近在学习Jquery的最新的源码,Jquery-3.3.1版本.网上有很多对jquery解析的文章.但是我还是要自己去尝试着看一篇jquery的源码.本系列博客用来记录其中的过程,并同大家分享.本次 ...
- JavaScript全讲-必知的特性
上篇讲完JS面向对象的特性,我们今天就来聊聊它的其它特性. JS面向对象的特性较为隐晦,真正使用也是比較少的.而今天我们要讲的,却是在实际开发中常常遇到的特性. 1. 函数式编程 多数人并不知道&qu ...