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.
39 lines
677 B
39 lines
677 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int INF = 0x3f3f3f3f;
|
|
|
|
const int N = 110;
|
|
int n, m;
|
|
int a[N][N];
|
|
int res = INF;
|
|
int f[N][N];
|
|
/*
|
|
动态规划
|
|
2 3
|
|
1 3 5
|
|
2 4 6
|
|
|
|
答案:
|
|
13
|
|
*/
|
|
|
|
int main() {
|
|
memset(f, 0x3f, sizeof f);
|
|
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= m; j++)
|
|
cin >> a[i][j];
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= m; j++) {
|
|
if (i == 1 && j == 1)
|
|
f[i][j] = a[i][j];
|
|
else
|
|
f[i][j] = min(f[i - 1][j], f[i][j - 1]) + a[i][j];
|
|
}
|
|
|
|
printf("%d\n", f[n][m]);
|
|
return 0;
|
|
} |