HDU1074:Doing Homework(状压DP)
Doing Homework
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15868 Accepted Submission(s): 7718
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.

题意:
有T测试用例,每个用例有个N门作业,每门作业有截止时间和完成所需的时间,默认时间为0,在截止时间过后每拖一天就会扣一分,求做作业的顺序让扣的分最少,如果有多个答案则输出字典序最小的答案(注意!),且输入的课程名称按字母顺序递增。
思路:
因为题目只有十五门课程,可以暴力状压DP,枚举1~1<<n的所有状态。具体见下代码。(不要在意头文件)
#define _CRT_SECURE_NO_DepRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cctype>
#include <iterator>
#include <vector>
#include <cstring>
#include <cassert>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define ll long long
#define INF 0x3f3f3f3f
#define ld long double
const ld pi = acos(-.0L), eps = 1e-;
int qx[] = { ,,,- }, qy[] = { ,-,, }, qxx[] = { ,- }, qyy[] = { ,- };
using namespace std;
struct node
{
string name;
int need, end;
}book[];
struct fate
{
int last, now, score, day;
}dp[<<];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
for (int i = ; i < n; i++)
{
cin >> book[i].name >> book[i].end >> book[i].need;
}
memset(dp, , sizeof(dp));
for (int i = ; i < << n; i++)//枚举做作业的每种情况
{
dp[i].score = INF;
for (int f = n - ; f >= ; f--)
{
int s = << f;//让1代表选择做哪一门课
if (s & i)//判断该情况是否有做这一门课
{
int last = i - s;//last为没做s这门课的时候
int score = max(dp[last].day + book[f].need - book[f].end, );//计算做s这门课的时候的分数,分数不能小于0
if (score + dp[last].score < dp[i].score)//如果做s这门课得分更少则做这么课
{
dp[i].score = score + dp[last].score;
dp[i].day = dp[last].day + book[f].need;
dp[i].last = last;//记录得分最少的上一种情况,记录路径
dp[i].now = f;//记录此时选做哪一门课,注意是倒着选的
}
}
}
}
cout << dp[( << n) - ].score << endl;//(1 << n) - 1的情况即为做全部作业的时候,DP的思想。
int out = ( << n) - ;
stack<string>output;
while (out)
{
output.push(book[dp[out].now].name);//因为是倒着记录的所以应用stack记录然后输出
out = dp[out].last;
}
while (!output.empty())
{
cout << output.top() << endl;
output.pop();
}
}
return ;
}
HDU1074:Doing Homework(状压DP)的更多相关文章
- HDU1074 Doing Homework —— 状压DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (J ...
- hdu_1074_Doing Homework(状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意:给你n个课程(n<=15)每个课程有限制的期限和完成该课程的时间,如果超出时间,每超 ...
- HDU 1074 Doing Homework 状压dp(第一道入门题)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1074 Doing Homework (状压DP)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1074 Doing Homework 状压DP
由于数据量较小,直接二进制模拟全排列过程,进行DP,思路由kuangbin blog得到,膜拜斌神 #include<iostream> #include<cstdio> #i ...
- kuangbin专题十二 HDU1074 Doing Homework (状压dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- Doing Homework HDU - 1074 (状压dp)
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...
- HDU 1074:Doing Homework(状压DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Problem Description Ignatius has just ...
随机推荐
- flask blueprint出现的坑
from flask import Blueprint admin = Blueprint('admin',__name__) def init_bule(app): app.register_blu ...
- Python卸载
前言 自己瞎折腾下载Python3.8.2,把之前下载好的python3.7.3覆盖掉.在运行之前Python环境的程序多次未果后.找到原因,Python3.7.3的包不支持Python3.8.2.于 ...
- java之线程中断——interrupt
如下图所示,interrupt()方法并没有成功的中断我们的线程. 为了便于理解,其实可以这样来类比(注意,只是类比,实际情况并不完全是这样):Thread类中有一个boolean的标志域用来表示线程 ...
- Java集合04——fail-fast&fail-safe 详解
在前几个回合中,我们已经详细了解过了 Java 集合中的List.Set 和 Map,对这部分内容感兴趣的朋友可以关注我的公众号「Java面典」了解.今天我们将为各位介绍集合的失败机制--fail-f ...
- Linux系统之LNMP及nginx反向代理实现
1.编译安装LNMP,并安装wordpress 首先准备环境,编译安装LNMP可以是多台主机,也可以是单台主机,把nginx,mysql,php都集中安装在一个主机上:我这里以一台主机为例吧!! 一. ...
- 手写redux方法以及数组reduce方法
reduce能做什么? 1)求和 2)计算价格 3)合并数据 4)redux的compose方法 这篇文章主要内容是什么? 1)介绍reduce的主要作用 2)手写实现reduce方法 0)了解red ...
- Nginx配置Web项目(多页面应用,单页面应用)
目前前端项目 可分两种: 多页面应用,单页面应用. 单页面应用 入口是一个html文件,页面路由由js控制,动态往html页面插入DOM. 多页面应用 是由多个html文件组成,浏览器访问的是对应服务 ...
- [译]ABP框架v2.3.0已经发布!
在新冠病毒的日子里,我们发布了ABP框架v2.3, 这篇文章将说明本次发布新增内容和过去的两周我们做了什么. 关于新冠病毒和我们的团队 关于冠状病毒的状况我们很难过.在Volosoft的团队,我们有不 ...
- python如何通过正则表达式一次性提取到一串字符中所有的汉字
1.python如何通过正则表达式一次性提取到一串字符中所有的汉字 https://blog.csdn.net/py0312/article/details/93999895 说明:字符串前的 “ r ...
- Javascript的document对象
对象属性 document.title //设置文档标题等价于HTML的<title>标签 document.bgColor / ...