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.
28 lines
569 B
28 lines
569 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
const int N = 110;
|
||
|
|
||
|
int n;
|
||
|
int w[N][N], f[N];
|
||
|
|
||
|
int main() {
|
||
|
cin >> n;
|
||
|
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[j] = w[i][j];
|
||
|
else
|
||
|
f[j] = min(f[j], f[j - 1]) + w[i][j];
|
||
|
}
|
||
|
printf("%d\n", f[n]);
|
||
|
return 0;
|
||
|
}
|