0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 06:28:47 +00:00
OI-codes/Luogu/P1130/P1130.cpp

26 lines
584 B
C++
Raw Normal View History

2021-11-19 09:01:13 +00:00
#include <bits/stdc++.h>
2020-11-01 08:49:20 +00:00
using namespace std;
int main() {
long long n, m, a[2005][2005], f[2005][2005];
cin >> n >> m;
2021-11-19 09:01:13 +00:00
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
2020-11-01 08:49:20 +00:00
cin >> a[j][i];
}
}
2021-11-19 09:01:13 +00:00
for (int i = 1; i <= n; i++) {
f[i - 1][0] = f[i - 1][m];
for (int j = 1; j <= m; j++) {
f[i][j] = a[i][j] + min(f[i - 1][j], f[i - 1][j - 1]);
2020-11-01 08:49:20 +00:00
}
}
long long ans = f[n][1];
2021-11-19 09:01:13 +00:00
for (int i = 2; i <= m; i++) {
2020-11-01 08:49:20 +00:00
ans = min(ans, f[n][i]);
}
cout << ans << endl;
return 0;
}