'commit'
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
|
||||
const int N = 110;
|
||||
int a[N][N];
|
||||
int n, m;
|
||||
int f[N][N];
|
||||
|
||||
// dfs解法
|
||||
/*
|
||||
2 3
|
||||
1 3 5
|
||||
2 4 6
|
||||
|
||||
答案:
|
||||
13
|
||||
*/
|
||||
|
||||
int dfs(int x, int y) {
|
||||
if (f[x][y]) return f[x][y];
|
||||
if (x > n || y > m) return INF;
|
||||
if (x == n && y == m) return a[n][m];
|
||||
return f[x][y] = a[x][y] + min(dfs(x + 1, y), dfs(x, y + 1));
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
cin >> a[i][j];
|
||||
|
||||
printf("%d\n", dfs(1, 1));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user