HDU 4848-Wow! Such Conquering!(DFS+最优性剪枝)
来源:互联网 发布:笔顺软件下载 编辑:程序博客网 时间:2024/05/22 06:31
Wow! Such Conquering!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 846 Accepted Submission(s): 255Problem DescriptionThere are n Doge Planets in the Doge Space. The conqueror of Doge Space is Super Doge, who is going to inspect his Doge Army on all Doge Planets. The inspection starts from Doge Planet 1 where DOS (Doge Olympic Statue) was built. It takes Super Doge exactly Txy time to travel from Doge Planet x to Doge Planet y.With the ambition of conquering other spaces, he would like to visit all Doge Planets as soon as possible. More specifically, he would like to visit the Doge Planet x at the time no later than Deadlinex. He also wants the sum of all arrival time of each Doge Planet to be as small as possible. You can assume it takes so little time to inspect his Doge Army that we can ignore it.InputThere are multiple test cases. Please process till EOF.Each test case contains several lines. The first line of each test case contains one integer: n, as mentioned above, the number of Doge Planets. Then follow n lines, each contains n integers, where the y-th integer in the x-th line is Txy . Then follows a single line containing n - 1 integers: Deadline2 to Deadlinen.All numbers are guaranteed to be non-negative integers smaller than or equal to one million. n is guaranteed to be no less than 3 and no more than 30.OutputIf some Deadlines can not be fulfilled, please output “-1” (which means the Super Doge will say “WOW! So Slow! Such delay! Much Anger! . . . ” , but you do not need to output it), else output the minimum sum of all arrival time to each Doge Planet.Sample Input40 3 8 64 0 7 47 5 0 26 9 3 030 8 3040 2 3 32 0 3 32 3 0 32 3 3 02 3 3Sample Output36-1题意:n个点,要求从1点开始跑,遍历所有点,要求到达每个点的时间<=time[i],求到达每个点时间的总和最小。爆搜+最优性剪枝+可行性剪枝(参考别人的)#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>#include <list>#define L long longusing namespace std;const int INF=0x3f3f3f3f;const int maxn=32;int dis[maxn][maxn];int n,tim[maxn];void Floyd(){for(int k=1;k<=n;k++)for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);}int vis[maxn],ans;void dfs(int src,int cur_time,int sum_time,int num){if(num==n){ans=min(ans,sum_time);return ;}//最优性剪枝:当前总时间+当前时间*剩余点数(因为往后到达的点的时间总是小于等于当前时间的)>=当前最优解 剪掉 int total=0; for(int i=2;i<=n;i++) { if(vis[i]==0) total+=dis[src][i]; } if(sum_time+cur_time*(n-num)+total>=ans)return ;//可行性剪枝:如果当前时间有超Deadtime的,剪掉for(int i=2;i<=n;i++)if(!vis[i]&&(cur_time+dis[src][i])>tim[i])return ;for(int i=2;i<=n;i++){if(src!=i&&!vis[i]&&cur_time+dis[src][i]<=tim[i]){vis[i]=1;dfs(i,cur_time+dis[src][i],sum_time+cur_time+dis[src][i],num+1);vis[i]=0;}}}int main(){while(~scanf("%d",&n)){memset(vis,0,sizeof(vis));for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&dis[i][j]);tim[1]=INF;for(int i=2;i<=n;i++)scanf("%d",&tim[i]);Floyd();vis[1]=1;ans=INF;dfs(1,0,0,1);if(ans==INF)ans=-1;printf("%d\n",ans);}return 0;}
阅读全文0 0
- HDU 4848-Wow! Such Conquering!(DFS+最优性剪枝)
- HDU 4848-Wow! Such Conquering!(DFS+最优性剪枝)
- HDU 4848 Wow! Such Conquering! (DFS)
- 【HDU】4848 Wow! Such Conquering! dfs爆搜+强力剪枝
- Hdu 4848 Wow! Such Conquering!(暴搜+剪枝)
- HDU 4848 Wow! Such Conquering! 搜索+剪枝
- HDU-4848 Wow! Such Conquering! 爆搜+剪枝
- hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)
- hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)
- hdu 4848 Wow! Such Conquering!(floyd+dfs)
- 最短路 + 搜索 + 剪枝 之 hdu 4848 Wow! Such Conquering!
- HDU 4848 Wow! Such Conquering! 暴搜+剪枝
- HDU 4848 Wow! Such Conquering! 深搜+强剪枝
- hdu 4848 Wow! Such Conquering!(搜索)
- HDU 4848 Wow! Such Conquering!
- HDU4848 Wow! Such Conquering! —— dfs + 剪枝
- HDOJ 4848 Wow! Such Conquering!
- [HDU 4848][2014西安全国邀请赛]Wow! Such Conquering!
- 根据某一属性对数组中的对象进行排序
- Java作业所有(一)
- 使用POI导入Excel文件数据
- 聚类LDA
- 每个踏上社会的童鞋们的方向
- HDU 4848-Wow! Such Conquering!(DFS+最优性剪枝)
- 有哪些通俗易懂的例子可以解释 IAAS、SAAS、PAAS 的区别?
- Spark 和 Hive之间的区别
- 利用SSH工具连接虚拟机上的CentOS 6.5
- 编写Spark SQL查询程序
- 关于同步异步、阻塞非阻塞的解释
- Android 数字显示带E(科学计数法)
- FreeSWITCH的端口设置
- CCF201612-1 中间数
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
成年蓝龙的肌腱掉落
蓝龙德怎么玩
巍山蓝龙花园酒店
漫威世界中的蓝龙
收蓟北
野蓝蓟
蓟北是哪里
白花藿香蓟
忽闻剑外收蓟北
飞蓟宾胶囊
代出自蓟北门行
剑外忽传收蓟北全诗
一捆血蓟
剑外忽闻收蓟北
蓟县
蓟县生活网
蓟县旅游
蓟县农家院
蓟县景点
蓟县招聘
蓟县招聘网
蓟县鲜花店
蓟县房价
蓟县教育网
蓟县在哪里
蓟县吧
蓟县生活
蓟县旅游网
蓟县特产
天津到蓟县
河北蓟县
天津市蓟县
蓟县新盘
蓟县采摘园
蓟县农家饭
蓟县楼盘
蓟县房产网
蓟县风景区
宝坻到蓟县
蓟县别墅
蓟县美容院