Doing Homework
来源:互联网 发布:网络公关公司良心哥 编辑:程序博客网 时间:2024/06/03 23:07
Doing Homework
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 30 Accepted Submission(s) : 21
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
2ComputerMathEnglish3ComputerEnglishMathHintIn 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<stdio.h>#include<string.h>#include<queue>#include<math.h>#include<list>#include<string>#include<set>#include<stack>#include<vector>#include<iostream>#include<iterator>#include<algorithm>using namespace std;struct node{int time;//截止时间int fen;//完成所需时长char kemu[105];} str[15];struct node1{int qian; //前一个状态int time; // 完成时间int fen; //扣分int a; // 记录路径} dp[1 << 15], stu;int vis[1 << 15];int main(){int t;scanf("%d", &t);while (t--){int n;scanf("%d", &n);getchar();for (int i = 0; i<n; i++){scanf("%s %d %d", str[i].kemu, &str[i].time, &str[i].fen);}memset(vis, 0, sizeof(vis));dp[0].qian = -1;dp[0].time = 0;dp[0].fen = 0;dp[0].a = -1;vis[0] = 1;for (int i = 0; i<long(1 << n); i++){for (int j = 0; j<n; j++){if ((i&(1 << j)) == 0) // 1<<j 位置的科目没有选{stu.qian = i;stu.time = dp[stu.qian].time + str[j].fen; // 到达当前状态 i|(1<<j) 花的总时间stu.fen = stu.time - str[j].time; // 完成该任务时的总时间—该任务的截止时间if (stu.fen<0) stu.fen = 0; // 未到截止时间 不扣分stu.fen += dp[stu.qian].fen;stu.a = j; // 该状态下完成的科目if (vis[i | (1 << j)]) // 当前状态之前出现{if (stu.fen<dp[i | (1 << j)].fen){dp[i | (1 << j)] = stu;}}else { dp[i | (1 << j)] = stu; vis[i | (1 << j)] = 1; }}}}stack<int>P;printf("%d\n", dp[(1 << n) - 1].fen);int k = (1 << n) - 1;for (int i = 0; i < n; i++){P.push(dp[k].a);k = dp[k].qian;}while (!P.empty()){k = P.top(); P.pop();printf("%s\n", str[k].kemu);}}return 0;}
0 0
- Doing Homework
- Doing Homework
- HDU 1074 Doing Homework
- HDUOJ1074 Doing Homework
- hdoj 1074 doing homework
- hdu 1074 Doing Homework
- HDU-1074-Doing Homework
- hdu-doing homework
- hdu 1074 Doing Homework
- hdu 1074 Doing Homework
- HDU1789:Doing Homework again
- HDU1789--Doing Homework again
- HDU1074--Doing Homework
- Doing Homework again
- HDU1074 Doing Homework
- Doing Homework again(dp)
- HDOJ 1074 Doing Homework
- hdu1789 Doing Homework again
- C#,Excel数据的导入、处理、导出
- Best of Sublime Text 3: Features, Plugins, and Settings
- 外观模式(Facade Pattern)小结
- Ubuntu 安装配置minicom
- 串口修改PAN ID和Channel
- Doing Homework
- 动态三维数组的创建与释放
- 前端开发神器 Emmet 介绍
- Struts2中访问web元素的四种方式及前台jsp页面获取后台值的方式
- WUBI安裝ubuntu 14.04过程及配置笔记
- 设计模式之代理模式
- 此次行程V型成V型成V型从
- HDOJ 4937 Lucky Number
- Graphviz