提交时间:2024-03-30 16:35:32

运行 ID: 140623

#include<bits/stdc++.h> using namespace std; int n,m; int k; double a[1010][1010]; double f[1010][1010]; signed main(){ cin >> n >> m; cin >> k; for(int i = 1;i <= k;i++){ int x,y; cin >> x>>y; a[x][y] = 1; } for(int i = 1;i <= n;i++){ f[i][0] = i*100; } for(int j = 1;j <= m;j++){ f[0][j] = j*100; } for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ if(a[i][j] == 0){ f[i][j] = min(f[i-1][j]+100,f[i][j-1]+100); }else if(a[i][j] == 1){ f[i][j] = min(min(f[i-1][j]+100,f[i][j-1]+100),f[i-1][j-1]+141.421356237); } } } cout << round(f[n][m]); return 0; }