Topic Portal
1 /*2 Test instructions: Known starting point (N), end point (n,m), from a point horizontal or vertical to the adjacent point distance +1, there are K shortcut diagonal +sqrt (2.0);3 recursive DP: Modeled Jayye, handled very cleverly, learning:)4 it seems to be scrolling the array, no, later5 */6#include <cstdio>7#include <iostream>8#include <algorithm>9#include <cmath>Ten#include <cstring> One using namespacestd; A - Const intMAXN = 1e3 +Ten; - Const intINF =0x3f3f3f3f; the DoubleDP[MAXN][MAXN]; - intUSED[MAXN][MAXN]; - intA[MAXN][MAXN]; - + intMainvoid)//URAL 1119 Metro - { +Freopen ("c.in","R", stdin); A at intN, M, K; - while(SCANF ("%d%d", &n, &m) = =2) - { -scanf ("%d", &k); - intu, v; -memset (Used,0,sizeof(used)); in while(k--) {scanf ("%d%d", &u, &v); USED[U][V] =true;} - to for(intI=0; i<=n; ++i) + { - for(intj=0; j<=m; ++j) the { * if(!i &&!j) dp[i][j] =0; $ Else if(!i) dp[1][J] = dp[1][j-1] +1;Panax Notoginseng Else if(!J) dp[1][J] = dp[0][J] +1; - Elsedp[1][j] = min (dp[1][j-1], dp[0][J]) +1; the if(Used[i][j]) dp[1][j] = min (dp[0][J] +1, dp[0][j-1] + sqrt (2.0)); + } A } the +printf ("%.0f\n", dp[1][M] * -); - $ } $ - return 0; -}
Recursive DP URAL 1119 Metro