【状压DP】【HDOJ1074】
http://acm.hdu.edu.cn/showproblem.php?pid=1074
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12269 Accepted Submission(s): 5911
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.
3
Computer 3 3
English 20 1
Math 3 2
3
Computer 3 3
English 6 3
Math 6 3
Computer
Math
English
3
Computer
English
Math
In the second test case, both Computer->English->Math and Computer->Math->English leads to reduce 3 points, but the
word "English" appears earlier than the word "Math", so we choose the first order. That is so-called alphabet order.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct sta {
char ss[];
int tim;
int del;
}st[],skt[<<];
int dp[ << ];
int pre[ << ];
void print(int x,int y) {
if (x == ) {
return;
}
print(x-(<<y), pre[x-(<<y)]);
printf("%s\n",st[y].ss);
}
int main() {
int t;
scanf("%d",&t);
while (t--) {
int n;
scanf("%d",&n);
for (int i = ; i < n; i++) {
scanf("%s%d%d",st[i].ss,&st[i].del,&st[i].tim);
}
memset(dp, 0x3f3f3f3f, sizeof(dp));
dp[] = ;
skt[].tim = ;
for (int i = ; i < ( << n); i++) {
for (int j = n - ; j >= ; j--) {
if (( << j)&i) {
int cost = skt[i - ( << j)].tim + st[j].tim - st[j].del;
if (cost < )cost = ;
if (cost + dp[i-(<<j)] < dp[i]) {
dp[i] = cost + dp[i - ( << j)];
skt[i].tim = skt[i - ( << j)].tim + st[j].tim;
pre[i] = j;
}
}
}
}
cout << dp[( << n) - ] << endl;
print((<<n)-,pre[(<<n)-]);
}
return ;
}
【状压DP】【HDOJ1074】的更多相关文章
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
- [NOIP2016]愤怒的小鸟 D2 T3 状压DP
[NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...
- 【BZOJ2073】[POI2004]PRZ 状压DP
[BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...
- bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)
数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
[BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...
随机推荐
- [IOS微信] Unicode码 转化为字符串
最近在研究IOS手机备份的数据,里面的微信数据中,每一个微信账号对应一个文件:mmsetting.archive 用来保存此账号的详细信息. 该文件是一个加强版的plist文件(此文件使用的是plis ...
- Android Touch事件之二:dispatchTouchEvent()和onTouchEvent()篇
2015-12-01 15:06:14 Android Touch事件第一篇:Touch事件在父ViewGroup和子View之间的传递简单分析了事件的传递流程,这次深入了解下dispatchTouc ...
- 三. Python基础(3)--语法
三. Python基础(3)--语法 1. 字符串格式化的知识补充 tpl = "我是%s,年龄%d,学习进度100%" %('Arroz',18) print(tpl) # 会提 ...
- :单件模式:Singleton
#ifndef __SINGLETON_H__ #define __SINGLETON_H__ class Singleton { private: static Singleton* instanc ...
- Spring boot 导出Excel
Html页面: window.location.href="adjectfkController/exportTemplate?adjOrg="+ adjOrg +"&a ...
- ln -s 软连接
创建软连接 ln -s 我们通过实例查看ls的路径发现,在/tmp/目录下的/bin/ls指向的是/usr/bin/ls,所以这里/tmp/bin/ls所存储的就是一个绝对路径,我们可以看做是一个软链 ...
- android 广播 接收短信
; i < messages.length; i++) { SmsMessage ms = SmsMessage.createFromPdu((byte[])pdus[i]); String f ...
- python 高级语言特性
装饰器decorator的使用 在某公司的一次笔试中面试官出了一道题,使用python 的decorator实现一个函数的执行时间的计算. 分析:关于函数执行时间的计算,那么肯定是执行之前得到一个时间 ...
- Python实现登陆的功能
import datetimetoday=datetime.datetime.today()# 获取当前时间for i in range(3): username=input("请输入用户名 ...
- mvc4使用百度ueditor编辑器
前言 配置.net mvc4项目使用ueditor编辑器,在配置过程中遇见了好几个问题,以此来记录解决办法.编辑器可以到http://ueditor.baidu.com/website/downloa ...