提交时间:2023-04-12 13:40:36

运行 ID: 74201

#include<bits/stdc++.h> using namespace std; double dp[1005][1005]; int pd[1005][1005]; int main(){ int n,m,k,x,y; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++){ scanf("%d%d",&x,&y); pd[x][y]=1; } for(int i=1;i<=n;i++){ dp[i][0]=i*100; } for(int i=1;i<=n;i++)dp[i][0]=i*100; for(int i=1;i<=m;i++)dp[0][i]=i*100; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(pd[i][j]==1){ dp[i][j]=min(min(dp[i-1][j]+100,dp[i][j-1]+100),dp[i-1][j-1]+141.42); } else{ dp[i][j]=min(dp[i-1][j]+100,dp[i][j-1]+100); } } } printf("%d",int(dp[n][m]+0.5)); return 0; }