AcWing 1018. 最低通行费
原题链接
简单
作者:
偷月亮的喵
,
2024-12-16 14:31:37
,
所有人可见
,
阅读 1
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
const int N = 110, INF = 1e9;
int n;
int w[N][N];
int f[N][N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &w[i][j]);
/* for (int i = 1; i <= n; i++) {
f[0][i] = INF;
f[i][0] = INF;
}*/
memset(f, 0x3f, sizeof f);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i == 1 && j == 1) f[i][j] = w[i][j]; // 特判左上角
else
{
f[i][j] = min(f[i - 1][j]+ w[i][j], f[i][j - 1]+ w[i][j]) ;
}
printf("%d ", f[n][n]);
printf("\n");
return 0;
}