标签:
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int inf = 0x3f3f3f3f; double dp[1005][1005]; int map1[1005][1005]; int main() { int n,m,k,x,y; while(~scanf("%d%d",&n,&m)){ scanf("%d",&k); memset(map1,0,sizeof(map1)); for(int i = 1; i <= k ;i++){ scanf("%d%d",&x,&y); map1[x+1][y+1] = 1; } for(int i = 0; i <= n+1; i++) for(int j = 0; j <= m+1; j++) dp[i][j] = inf; dp[1][1] = 0; for(int i = 1; i <= n+1; i++){ for(int j = 1 ; j <= m+1 ;j++){ if(i == 1 && j == 1) continue; if(map1[i][j] == 1) dp[i][j] = min(min(dp[i][j-1]+100,dp[i-1][j]+100),dp[i-1][j-1]+100*sqrt(2)); else dp[i][j] = min(dp[i][j-1]+100,dp[i-1][j]+100); } } printf("%.0lf\n",dp[n+1][m+1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4483074.html