提交时间:2024-03-30 15:53:35

运行 ID: 140561

#include<bits/stdc++.h> #define int long long using namespace std; double dp[1005][1005]; bool f[1005][1005]; signed main(){ //freopen("a.txt","r",stdin); int n,m,k; cin>>n>>m>>k; for (int i = 1;i <= k;i++){ int x,y; cin>>x>>y; f[x][y] = true; } for (int i = 0;i <= n + 1;i++){ for (int j = 0;j <= m + 1;j++){ dp[i][j] = 200000007.0; } } dp[1][1] = 0.0; for (int i = 1;i <= n + 1;i++){ for (int j = 1;j <= m + 1;j++){ if (i == 1 && j == 1){ continue; } dp[i][j] = min(dp[i - 1][j],dp[i][j - 1]) + 100.0; if (f[i - 1][j - 1]){ dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + sqrt(20000.0)); } } } cout<<(long long)(dp[n + 1][m + 1] + 0.5); return 0; }