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 ...
随机推荐
- 【06】openlayers 切片图层
创建地图: //OSM图层 let source = new ol.source.OSM() //切片图层tilelayer let layers = new ol.layer.Tile({ sour ...
- DevOps - 持续集成
最近在担任公司部门的DevOps Champion的角色,一直觉得这个只是一个协调者的角色(而不是一个SME的角色),我的工作大概就是将每个项目的devops工具收集一下,然后用图表的形式去体现大家用 ...
- 简述树,Trie,Avl,红黑树
树的表示方法 在平时工作中通常有2种方式来表示树状结构,分别是孩子链表示法和父节点表示法.光说名词可能无法让人联系到实际场景中,但是写出代码之后大家一定就明白了. 孩子链表示法,即将树中的每个结点的孩 ...
- Go 的 http 包的源码,通过代码我们可以看到整个的 http 处理过程
func (srv *Server) Serve(l net.Listener) error {defer l.Close() var tempDelay time.Duration // how l ...
- nuxt.js如何实现同级目录下建多个动态路由,并将链接设置.html后缀
nuxt.js中如果在同级目录中建两个_xxxx.vue的动态路由文件,那么页面跳转始终是跳的一个页面,如何解决这个问题呢?下面举个栗子: 第一步:新建两个页面文件 第二步:在nuxt.config. ...
- Spark入门(二)--如何用Idea运行我们的Spark项目
用Idea搭建我们的Spark环境 用IDEA搭建我们的环境有很多好处,其中最大的好处,就是我们甚至可以在工程当中直接运行.调试我们的代码,在控制台输出我们的结果.或者可以逐行跟踪代码,了解spark ...
- Mysql优化大分页查询
如题,年前做了一个需求,涉及到Mysql大分页查询,整理一下,希望对需要的小伙伴有帮助. 背景分页查询的性能瓶颈B+树简述B+比起二叉查找树,有什么优势?分页查询过程测试集解决方法1 延迟关联法:2 ...
- IdentityServer4实现.Net Core API接口权限认证(快速入门)
什么是IdentityServer4 官方解释:IdentityServer4是基于ASP.NET Core实现的认证和授权框架,是对OpenID Connect和OAuth 2.0协议的实现. 通俗 ...
- ProjectTool写白包工具,秒级别写H5游戏壳包,可视化操作,极易使用,支持Swift、Objecive-C双语言
这是自动写白包工具,秒级别写H5游戏壳包,可视化操作,极易使用,支持Swift.Objecive-C双语言 扣扣交流群:811715780 [ 官网下载 ] 这是一个白包目录示例 ProjectToo ...
- NeurIPS 2019 | 基于Co-Attention和Co-Excitation的少样本目标检测
论文提出CoAE少样本目标检测算法,该算法使用non-local block来提取目标图片与查询图片间的对应特征,使得RPN网络能够准确的获取对应类别对象的位置,另外使用类似SE block的sque ...