HDU_1074_Doing Homework_状态压缩dp
链接: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): 7543 Accepted Submission(s): 3375
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>
- #include<algorithm>
- #include<stack>
- using namespace std;
- const int INF=<<;
- struct Node
- {
- char name[];
- int dead,cost;
- }cla[];
- struct DP
- {
- int pre,time,spent,now;
- }dp[<<];
- int main()
- {
- int t,i,j,s,n,end;
- //scanf("%d",&t);
- cin>>t;
- while(t--)
- {
- memset(dp,,sizeof(dp));
- //scanf("%d",&n);
- cin>>n;
- for(int i=;i<n;i++)
- //scanf("%s%d%d",cla[i].name,&cla[i].dead,&cla[i].cost);
- cin>>cla[i].name>>cla[i].dead>>cla[i].cost;
- int en=<<n;
- for(int s=;s<en;s++)
- {
- dp[s].spent=INF;
- for(int i=n-;i>=;i--)
- {
- int tem=<<i;
- if(s&tem)
- {
- int past=s-tem;
- int st=dp[past].time+cla[i].cost-cla[i].dead;
- if(st<)
- st=;
- if(dp[s].spent>dp[past].spent+st)
- {dp[s].spent=dp[past].spent+st;
- dp[s].now=i;
- dp[s].pre=past;
- dp[s].time=dp[past].time+cla[i].cost;
- }
- }
- }
- }
- stack<int> S;
- int tem = en-;
- cout << dp[tem].spent << endl;
- while(tem)
- {
- S.push(dp[tem].now);
- tem = dp[tem].pre;
- }
- while(!S.empty())
- {
- cout << cla[S.top()].name << endl;
- S.pop();
- }
- }
- return ;
- }
HDU_1074_Doing Homework_状态压缩dp的更多相关文章
- 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][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- 【Hibernate学习】 ——ORM(一)
Hibernate是一种能实现ORM的框架. ORM即Object Relational Mapping.对象关系映射.也就是将关系数据库中表的数据映射成为对象.也就是说将表与表之间的操作映射成对象与 ...
- alias记录
在seajs里边会有配置alias对象属性的,这个就是一个别名,下次在模块加载的时候直接引用别名就好了. 别名配置,配置之后可在模块中使用require调用 require('jquery'); se ...
- 通过java类文件识别JDK编译版本号
类文件里第5,6.7,8四个字节是jDK版本信息.当中5,6为小版本:7,8为大版本. 大版本号号相应JDK版本号例如以下: JDK版本 7,8字节 JDK8 52(0x34) JDK7 51(0x3 ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D "Or" Game 枚举+前缀后缀
D. "Or" Game ...
- Jenkins CLI 使用
//链接java -jar jenkins-cli.jar -s JenkinsHost who-am-i --username 用户名 --password 密码 删除Jobjava -jar je ...
- 在mac下设置环境变量
在mac下设置环境变量 在基于unix/linux的操作系统下进行程序开发,使用环境变量将会方便.通过设置环境变量将可以在任意目录通过输入程序名来执行设定目录下的程序.不需要通过cd将工作目录改变 ...
- 【bug】QUOTA_EXCEEDED_ERR: DOM Exception 22
iOS的Safari在无痕模式下,sessionStorage操作产生异常,报错QUOTA_EXCEEDED_ERR: DOM Exception 22. html5 localStorage err ...
- Java IO流中 File文件对象与Properties类(四)
File类 用来将文件或目录封装成对象 方便对文件或目录信息进行处理 File对象可以作为参数传递给流进行操作 File类常用方法 创建 booleancreateNewFile():创建新文件,如果 ...
- Linux 系统命令 - pwd - 显示当前所在的位置
命令详解 重要星级: ★★★★★ 功能说明: pwd命令是 "print working directory" 中每个单词的首字母缩写,其功能是显示当前工作目录的绝对路径.在实际工 ...
- bzoj 4031: [HEOI2015]小Z的房间【矩阵树定理】
是板子题,因为mod不是质数所以需要辗转相除然而并不知道为啥 高斯消元部分还不知道原理呢--先无脑背过的 #include<iostream> #include<cstdio> ...