You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
661 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n;
int w[N][N], f[N][N];
int main() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> w[i][j];
// 初始化为最大值
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], f[i][j - 1]) + w[i][j];
}
printf("%d\n", f[n][n]);
return 0;
}