[HDU 4848][2014西安全国邀请赛]Wow! Such Conquering!
来源:互联网 发布:王兆山 真相 知乎 编辑:程序博客网 时间:2024/04/30 16:54
There 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.
首先注意题目给出的邻接矩阵并不一定是最短路,所以先用Floyd求出最短路,然后暴力搜索。
注意几个剪枝:
1,由于当前到达时间是递增的,所以若当前的消耗总时间+当前时间x剩余星球数量若大于已求出的最小值,剪枝。
2,若存在星球已超出访问时间限制,剪枝。
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n,d[35][35],lim[35],vis[35],m=0x3ffffff;void dfs(int deep,int cur,int time,int tot){ if(tot+(n-deep)*time>m)return; if(deep==n){if(m>tot)m=tot;return;} int i,temp; for(i=2;i<=n;i++) if(vis[i]==0&&time>lim[i])return; for(i=2;i<=n;i++){ if(vis[i]||tot+(n-deep)*d[cur][i]>=m)continue ; temp=time+d[cur][i]; if(temp<=lim[i]){ vis[i]=vis[i]|1; dfs(deep+1,i,temp,tot+temp); vis[i]=0; } }}int main(){ while(scanf("%d",&n)>0){ memset(vis,0,sizeof(vis)); m=0x3ffffff; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&d[i][j]); for(int i=2;i<=n;i++)scanf("%d",&lim[i]); for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]); dfs(1,1,0,0); if(m<0x3ffffff)printf("%d\n",m);else printf("%d\n",-1); }}
0 0
- [HDU 4848][2014西安全国邀请赛]Wow! Such Conquering!
- hdu 4850 Wow! Such String! 2014西安全国邀请赛
- 2014西安全国邀请赛 1003 && HDU 4849 Wow! Such City! (单源最短路Djikstra算法)
- HDU 4848 Wow! Such Conquering!
- HDU 4850 2014西安邀请赛 D题 Wow! Such String!
- hdu 4848 Wow! Such Conquering!(搜索)
- Hdu 4848 Wow! Such Conquering!(暴搜+剪枝)
- HDU 4848 Wow! Such Conquering! (DFS)
- HDU 4848 Wow! Such Conquering! 搜索+剪枝
- HDU-4848 Wow! Such Conquering! 爆搜+剪枝
- 2014西安全国邀请赛——题目重现(感谢西工大+复旦)HDOJ4847 Wow! Such Doge!
- 2014西安全国邀请赛——题目重现(感谢西工大+复旦 HDOJ 4849 Wow! Such City!
- hdu 4849 最短路 西安邀请赛 Wow! Such City!
- HDOJ 4848 Wow! Such Conquering!
- HDU 4849 2014西安邀请赛 C题 Wow! Such City! 最短路
- hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)
- hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)
- 【HDU】4848 Wow! Such Conquering! dfs爆搜+强力剪枝
- 2014-08-04 日志
- HDU 4908 BestCoder Sequence (hash)
- Android常用Adapter用例
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- Eclipse快捷键
- [HDU 4848][2014西安全国邀请赛]Wow! Such Conquering!
- JAVA中的复用类:继承、组合和代理
- iOS7开发~企业发布
- Openstack 出现"Failed to connect to server (code: 1006)“总结
- OC中循环导入的问题,及解决办法.
- vc6.0实现操作excle之下篇
- HDUJ 2076 夹角有多大(题目已修改,注意读题)
- history
- 用NPOI将DataGridView中需要的列导出为Excel