HDU-4848 Wow! Such Conquering! (回溯+剪枝)
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.
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.
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.
# include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std;
# define LL long long
const int INF=1<<30;
int mp[35][35],n,a[35],ans,vis[35];
void floyd()
{
for(int k=0;k<n;++k)
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
}
void dfs(int cur,int time,int att,int num)
{
if(num==n){
ans=min(ans,att);
return ;
}
if(att+(n-num)*time>=ans)
return ;
for(int i=1;i<n;++i)
if(!vis[i]&&time+mp[cur][i]>a[i])
return ;
for(int i=1;i<n;++i){
if(vis[i])
continue;
vis[i]=1;
dfs(i,time+mp[cur][i],att+time+mp[cur][i],num+1);
vis[i]=0;
}
}
int main()
{
while(~scanf("%d",&n))///在这里如果用“!=EOF”会超时。
{
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
scanf("%d",&mp[i][j]);
floyd();
a[0]=0;
for(int i=1;i<n;++i)
scanf("%d",a+i);
memset(vis,0,sizeof(vis));
ans=INF;
vis[0]=1;
dfs(0,0,0,1);
if(ans!=INF)
printf("%d\n",ans);
else
printf("-1\n");
}
return 0;
}
HDU-4848 Wow! Such Conquering! (回溯+剪枝)的更多相关文章
- hdu 4848 Wow! Such Conquering! (floyd dfs)
Wow! Such Conquering! Problem Description There are n Doge Planets in the Doge Space. The conqueror ...
- HDU 4848 - Wow! Such Conquering!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Descriptio ...
- HDU 5113 Black And White 回溯+剪枝
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5113 Black And White Time Limit: 2000/2000 MS (Java/ ...
- HDU 2553 N皇后问题(回溯 + 剪枝)
本文链接:http://i.cnblogs.com/EditPosts.aspx?postid=5398797 题意: 在N*N(N <= 10)的方格棋盘放置了N个皇后,使得它们不相互攻击(即 ...
- HDU4848 Wow! Such Conquering! —— dfs + 剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4848 题解: 一开始读错题目.以为每个点只能访问一遍.其实只要每个点都有被访问就可以了. 首先是用弗洛 ...
- HDU-4848 Wow! Such Conquering! 爆搜+剪枝
Wow! Such Conquering! 题意:一个n*n的数字格,Txy表示x到y的时间.最后一行n-1个数字代表分别到2-n的最晚时间,自己在1号点,求到达这些点的时间和的最少值,如果没有满足情 ...
- hdu 4850 Wow! Such String! 欧拉回路
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- HDU1010 Tempter of the Bone(回溯 + 剪枝)
本文链接:http://i.cnblogs.com/EditPosts.aspx?postid=5398734 题意: 输入一个 N * M的迷宫,这个迷宫里'S'代表小狗的位置,'X'代表陷阱,‘D ...
- HDU1016 Prime Ring Problem (回溯 + 剪枝)
本文链接:http://www.cnblogs.com/Ash-ly/p/5398684.html 题意: 给你一个数字N(N <= 20),要求你把这N个数组成一个环,环内的数字不能重复,左右 ...
随机推荐
- mysql多实例安装与ssl认证
mysql多实例安装有两种形式: 同一数据库版本的多实例安装. 不同数据库版本的多实例安装. 同一数据库的多实例安装: 在同一台机器上安装4台mysql数据库实例. 从官网下载MySQL5.6版本的二 ...
- VIM 使用心得
序 到百度外卖任职以后,发现在我们部门无论 mac 还是 windows,程序员们清一色地都在使用 VIM 来编辑代码,期间穿插着各种插件.快捷键.眼花缭乱的命令.我在大学时只会极少的 VIM 命令, ...
- 20135234mqy-——信息安全系统设计基础第五周学习总结
程序的机器级表示 3.1 intel处理器系列俗称x86,经历了一开始个长期的,不断进化的发展过程. 开始时它是第一代单芯片,16位微处理器之一,由于当时集成电路技术水性有限,其中做了很多妥协,此后, ...
- 实验二Java面向对象程序设计
一.单元测试 了解三种代码: 1.伪代码:类似于自然语言说明,描述实现逻辑思维 2.产品代码:程序员编辑的开发代码,要求可修改.可移植 3.测试代码:我理解是相当于开发软件在软件开放之前,程序员找到b ...
- VC++实现获取文件占用空间大小的两种方法(非文件大小)
// GetFileSpaceSize.cpp : Defines the entry point for the console application. // /***************** ...
- HDU3652 B-number(数位DP)题解
思路: 这里的状态分为3种,无13和末尾的1,无13且末尾为1,有13,然后DFS 等我搞清楚数位DP就来更新Orz 代码: #include<iostream> #include< ...
- 【旧版本】Ubuntu 14.04 下 P416编译器 p4c的安装
注:此为2017年5月份的安装方法,最新的p4c安装方法见: Ubuntu14.04下 安装p4c 参考: p4c README Ubuntu 14.04 下 P4v16编译器 p4c的安装 系统要求 ...
- spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes
spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web serv ...
- Python matplot的使用(一)
其实,使用它的直接原因是因为matlab太大了,不方便.另外,就是它是免费的. 在安装这个库的时候,会需要安装一些它所依赖的库,比如six等.从sourceforge上下载,只需按照提示安装完成就行了 ...
- Jmeter 同一个测试计划下的多个线程组 执行顺序 希望调整为顺序执行
用Jmeter做自动化测试,一个测试计划中添加多个线程组, 每个线程组的功能测试,希望是一个线程组执行完毕后,接着执行下一个线程组下的请求 Jmeter默认多个线程组之间是并行关系 需要在测试计划下勾 ...