状态压缩DP
来源:互联网 发布:笔记本win10优化教程 编辑:程序博客网 时间:2024/06/01 19:21
Doing Homework
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 10
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test, 1 day for 1 point. And as you know, doing homework always takes a long time. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
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.
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.
Output
For each test case, you should output the smallest total reduced score, then give out the order of the subjects, one subject in a line. If there are more than one orders, you should output the alphabet smallest one.
Sample Input
23Computer 3 3English 20 1Math 3 23Computer 3 3English 6 3Math 6 3
Sample Output
2ComputerMathEnglish3ComputerEnglishMath代码: #include"stdio.h"#include"string.h"#define Max 1<<16struct node{ int cost; int pre; int reduced;}dp[Max];struct Cou{ int deadt; int cost; char name[110];}cou[16];int vis[Max];void output(int k){ int curj=dp[k].pre^k; int curi=0; curj>>=1; while(curj) { curi++; curj>>=1; } if(dp[k].pre) output(dp[k].pre); printf("%s\n",cou[curi].name);}int main(){ int t,n,i,j; int u,day,cur,temp,re; scanf("%d",&t); while(t--) { scanf("%d",&n); u=(1<<n)-1; for(i=0;i<n;i++) scanf("%s %d%d",cou[i].name,&cou[i].deadt,&cou[i].cost); memset(vis,0,sizeof(vis)); dp[0].cost=0; dp[0].pre=-1; dp[0].reduced=0; vis[0]=1; for(i=0;i<u;i++) { for(j=0;j<n;j++) { cur=1<<j; if((cur&i)==0) { temp=cur|i; day=dp[i].cost+cou[j].cost; dp[temp].cost=day; re=day-cou[j].deadt; if(re<0)re=0; re+=dp[i].reduced; if(vis[temp]) { if(re<dp[temp].reduced) { dp[temp].reduced=re; dp[temp].pre=i; } } else { vis[temp]=1; dp[temp].reduced=re; dp[temp].pre=i; } } } } printf("%d\n",dp[u].reduced); output(u); } return 0;}
0 0
- 状态压缩dp
- pku1038状态压缩dp
- 状态压缩DP 入门
- HDU1074 状态压缩DP
- Poj3254 状态压缩DP
- 状态压缩DP入门
- 【状态压缩DP】互不侵犯
- 【状态压缩DP】电子竞技
- HDU1074 状态压缩DP
- 【状态压缩DP】互不侵犯
- 状态压缩 DP AHU420
- HDU2167 状态压缩DP
- SGU223 -状态压缩DP
- poj3254 状态压缩dp
- 状态压缩dp poj1185
- DP(2) 状态压缩
- poj2430 状态压缩DP
- hdu4628状态压缩DP
- ios--UIPageControl
- iOS开发最新参考书籍 iOS7
- 当数据库很慢时考察的一些计数器
- springMVC无法访问JSP报404,但是又能访问controller
- android--笔记--隐藏软键盘
- 状态压缩DP
- Unity3D研究院之IOS触摸屏手势控制镜头旋转与缩放
- Prime Distance(二次筛素数)
- 简单了解struts2的上下文
- google在当今网络时代的重要性已经是不言而喻的了
- 接口
- Impala/Hive现状分析与前景展望
- 4种必须知道的Android屏幕自适应解决方案
- 标准的Java连接Oracle数据库的示例代码