Doing Homework (状态dp)
来源:互联网 发布:淘宝怎样申请退货退款 编辑:程序博客网 时间:2024/05/28 06:05
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.
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.
23Computer 3 3English 20 1Math 3 23Computer 3 3English 6 3Math 6 3
2ComputerMathEnglish3ComputerEnglishMath
题目大概:
给出n门课的作业,完成的最后期限和需要花费的时间,当一门作业晚了,晚1天扣一分。问最少减几分,并且输出课的顺序。
思路:
状态dp
dp【i】表示到i状态的时候的最少的减分。
代码:
#include <iostream>#include <cstdio>using namespace std;const int ma=(1<<16);int inf=1<<30;int dp[ma],t[ma],qian[ma],dea[ma],hua[ma];char s[20][110];int n;void outa(int x){ if(!x)return; outa(x-(1<<qian[x])); printf("%s\n",s[qian[x]]);}int main(){ int m; scanf("%d",&m); while(m--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s%d%d",s[i],&dea[i],&hua[i]); } for(int i=1;i<1<<n;i++)//枚举每一个状态 { dp[i]=inf; for(int j=n-1;j>=0;j--)//枚举每一门课 { int tem=1<<j; if(i&tem)//本门课是否在状态内 { int score=t[i-tem]+hua[j]-dea[j];//计算从没有做这门课到做这门课的分数的变化 if(score<0)score=0; if(dp[i]>dp[i-tem]+score)//符合条件更新 { dp[i]=dp[i-tem]+score; t[i]=t[i-tem]+hua[j]; qian[i]=j; } } } } int ans=1<<n; printf("%d\n",dp[ans-1]); outa(ans-1);//顺序输出 } return 0;}
阅读全文
0 0
- Doing Homework (状态dp)
- hdu1074 Doing Homework(状态压缩dp)
- hdu1074 Doing Homework (状态压缩dp)
- HDU 1074 Doing Homework(状态DP)
- Doing Homework(数塔型状态DP)
- hdu 1074 Doing Homework(状态压缩DP)
- HDU 1074Doing Homework(状态压缩dp)
- hdu 1074 Doing Homework (状态压缩 dp)
- hdu 1074 Doing Homework (状态压缩dp)
- HDU 1074 Doing Homework(状态压缩dp)
- HDU1074——Doing Homework(状态压缩DP)
- HDU 1074 Doing Homework(状态压缩 + DP)
- !HDU 1074 Doing Homework--DP--(状态压缩)
- HDOJ 1074.Doing Homework(状态压缩DP)
- HDU 1074 Doing Homework(DP·状态压缩)
- HDU 1074 Doing Homework(状态压缩DP)
- hdu 1074 Doing Homework(状态压缩dp)
- (HDU 1074)Doing Homework dp 状态压缩
- ZK2
- kuangbin专题五 并查集 POJ1733 Parity game
- 黑龙江省对地观测与导航工程技术研究中心正式通过科技厅备案
- Java-集合 list对象进行指定位置插入、删除、迭代、遍历输出(具体习题讲解)
- RecyclerView的使用
- Doing Homework (状态dp)
- Win10升级后VMWare内的系统连不了网如何解决
- Python安装第三方模块
- 11月27号 侧边
- EvenBus
- Did you smile today?
- 图像几何运算
- jQuery插件开发精品教程,让你的jQuery提升一个台阶
- MySQL5.7 InnoDB Page Compression