标签:
1 /*
2 题意:已知起点(1,1),终点(n,m);从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0);
3 递推DP:仿照JayYe,处理的很巧妙,学习:)
4 好像还要滚动数组,不会,以后再补
5 */
6 #include <cstdio>
7 #include <iostream>
8 #include <algorithm>
9 #include <cmath>
10 #include <cstring>
11 using namespace std;
12
13 const int MAXN = 1e3 + 10;
14 const int INF = 0x3f3f3f3f;
15 double dp[MAXN][MAXN];
16 int used[MAXN][MAXN];
17 int a[MAXN][MAXN];
18
19 int main(void) //URAL 1119 Metro
20 {
21 freopen ("C.in", "r", stdin);
22
23 int n, m, k;
24 while (scanf ("%d%d", &n, &m) == 2)
25 {
26 scanf ("%d", &k);
27 int u, v;
28 memset (used, 0, sizeof (used));
29 while (k--) {scanf ("%d%d", &u, &v); used[u][v] = true;}
30
31 for (int i=0; i<=n; ++i)
32 {
33 for (int j=0; j<=m; ++j)
34 {
35 if (!i && !j) dp[i][j] = 0;
36 else if (!i) dp[1][j] = dp[1][j-1] + 1;
37 else if (!j) dp[1][j] = dp[0][j] + 1;
38 else dp[1][j] = min (dp[1][j-1], dp[0][j]) + 1;
39 if (used[i][j]) dp[1][j] = min (dp[0][j] + 1, dp[0][j-1] + sqrt (2.0));
40 }
41 }
42
43 printf ("%.0f\n", dp[1][m] * 100);
44
45 }
46
47 return 0;
48 }
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4482955.html