题意:有A个村庄,B个城市,m条边,从起点到终点,找一条最短路径。但是,有一种工具可以使人不费力的移动L个长度,但始末点必须是城市或村庄。这种工具有k个,每个只能使用一次,并且在城市内部不可使用,但在村庄内部可使用。另外,在城市或村庄内部的时间不计。

析:先预处理出来使用工具能到达的距离,这个可以用Floyd 来解决,然后f[i][u] 表示到达 u 还剩下 i 次工具未用,然后用bfs就可以很简单的解决。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 10;
const int maxm = 1e5 + 10;
const int mod = 50007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} int dp[maxn][maxn];
int f[12][maxn]; int main(){
int T; cin >> T;
while(T--){
int A, B, L, K;
scanf("%d %d %d %d %d", &A, &B, &m, &L, &K);
ms(dp, INF);
while(m--){
int u, v, c; scanf("%d %d %d", &u, &v, &c);
dp[u][v] = dp[v][u] = min(c, dp[u][v]);
}
FOR(k, 1, A+1) FOR(i, 1, A+B+1) FOR(j, 1, A+B+1)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
ms(f, INF); f[K][A+B] = 0;
queue<P> q; q.push(P(K, A+B));
while(!q.empty()){
P p = q.front(); q.pop();
int u = p.se, i = p.fi;
for(int v = 1; v < A+B; ++v){
if(dp[u][v] == INF || u == v) continue;
if(f[i][v] > f[i][u] + dp[u][v]){
f[i][v] = f[i][u] + dp[u][v];
q.push(P(i, v));
}
if(i && f[i-1][v] > f[i][u] && L >= dp[u][v]){
f[i-1][v] = f[i][u];
q.push(P(i-1, v));
}
}
}
int ans = INF;
for(int i = 0; i <= K; ++i) ans = min(ans, f[i][1]);
printf("%d\n", ans);
}
return 0;
}

  

UVa 10269 Adventure of Super Mario (Floyd + DP + BFS)的更多相关文章

  1. UVA10269 Adventure of Super Mario(Floyd+DP)

    UVA10269 Adventure of Super Mario(Floyd+DP) After rescuing the beautiful princess, Super Mario needs ...

  2. ZOJ 1232 Adventure of Super Mario (Floyd + DP)

    题意:有a个村庄,编号为1到a,有b个城堡,编号为a+1到a+b.现在超级玛丽在a+b处,他的家在1处.每条路是双向的,两端地点的编号以及路的长度都已给出.路的长度和通过所需时间相等.他有一双鞋子,可 ...

  3. UVA 10269 Adventure of Super Mario

    看了这里 http://blog.csdn.net/acm_cxlove/article/details/8679230的分析之后自己又按照自己的模板写了一遍,算是对spfa又加深了一步认识(以前真是 ...

  4. ZOJ1232 Adventure of Super Mario(DP+SPFA)

    dp[u][t]表示从起点出发,到达i点且用了t次magic boot时的最短时间, 方程如下: dp[v][t]=min(dp[v][t],dp[u][t]+dis[u][v]); dp[v][t] ...

  5. ZOJ1232 Adventure of Super Mario spfa上的dp

    很早之前听说有一种dp是在图上的dp,然后是在跑SPFA的时候进行dp,所以特地找了一题关于在SPFA的时候dp的. 题意:1~a是村庄 a+1~a+b是城堡,存在m条无向边.求由a+b->1的 ...

  6. [题解]UVA10269 Adventure of Super Mario

    链接:http://vjudge.net/problem/viewProblem.action?id=24902 描述:由城镇.村子和双向边组成的图,从A+B走到1,要求最短路.有K次瞬移的机会,距离 ...

  7. UVA-10269 Adventure of Super Mario (dijkstra)

    题目大意:有A个村庄,B个城市,m条边,从起点到终点,找一条最短路径.但是,有一种工具可以使人不费力的移动L个长度,但始末点必须是城市或村庄.这种工具有k个,每个只能使用一次,并且在城市内部不可使用, ...

  8. zoj1232Adventure of Super Mario(图上dp)

    题目连接: 啊哈哈.点我点我 思路: 这个题目是一个图上dp问题.先floyd预处理出图上全部点的最短路,可是在floyd的时候,把可以用神器的地方预处理出来,也就是转折点地方不能为城堡..预处理完成 ...

  9. ACM/ICPC 之 最短路-Floyd+SPFA(BFS)+DP(ZOJ1232)

    这是一道非常好的题目,融合了很多知识点. ZOJ1232-Adventrue of Super Mario 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...

随机推荐

  1. as3 判断鼠标移动方向

    import flash.events.MouseEvent; var odx:Number=mouseX; var ody:Number=mouseY; stage.addEventListener ...

  2. struts2,servlet和springmvc的单例多例问题

    struts2,servlet和springmvc的单例多例问题 原创 2017年06月12日 09:59:21 标签: struts2 / servlet / springmvc / 单例 / 多例 ...

  3. unity 加载读取外部XML

    cfg.xml <rootNode> <category name="网站"> <item name="mainPage"> ...

  4. Functional Java 学习笔记

    Functional Java Functional Java是一个在Java语言中实现函数型编程范式的类库. 从接口上看,该类库似乎与Haskell语言关系密切,接口的方法名很多来自该语言. < ...

  5. 树莓派 Zero W+温度传感器DS18B20

    树莓派 Zero W+温度传感器DS18B20 作者:陈拓chentuo@ms.xab.ac.cn 2018.05.28/2018.06.01 0.  概述 用树莓派 Zero W读取DS18B20温 ...

  6. conductor 系统任务

    动态任务: 参数: dynamicTaskNameParam:来自任务输入的参数的名称,其值用于调度任务. 例如 如果参数的值为ABC,则调度的下一个任务类型为“ABC”. Example { &qu ...

  7. Gviz

    1) Introduction 为了理解基因组数据,通常旨在在基因组浏览器中绘制这样的数据,以及各种基因组注释特征,例如基因或转录物模型,CpG岛,重复区域等.这些功能可以从ENSEMBL或UCSC等 ...

  8. BlockingQueue深入解析-BlockingQueue看这一篇就够了

    本篇将详细介绍BlockingQueue,以下是涉及的主要内容: BlockingQueue的核心方法 阻塞队列的成员的概要介绍 详细介绍DelayQueue.ArrayBlockingQueue.L ...

  9. MySql的基本架构续

    [数据拆分后引入的问题] 数据水平拆分引入的问题主要是只能通过sharding key来读写操作,例如以userid为sharding key的切分例子,读userid的详细信息时,一定需要先知道us ...

  10. 关于easyui-datagrid数据表格, 分页取出数据

    在制作数据表格的时候有一个这样的属性, pagination是否显示分页列表, 分页显示的时候需要分别从数据库中取数据, 每页显示几行, 即只从数据库取出几行数据来显示, 具体代码如下 1, 显示页面 ...