-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11048.cpp
More file actions
51 lines (35 loc) · 719 Bytes
/
11048.cpp
File metadata and controls
51 lines (35 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#include <iostream>
using namespace std;
int n, m;
int map[1001][1001];
int dp[1001][1001];
int main() {
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
cin >> n>> m;
for (int i = 1;i <= n;i++) { //map ¸¸µå´Â ¹è¿
for (int j = 1;j <= m;j++) {
cin >> map[i][j];
}
}
for (int j = 1;j <= m;j++) {
dp[1][j] = map[1][j]+dp[1][j-1];
}
for (int i = 1;i <= n;i++) {
dp[i][1] = map[i][1]+dp[i-1][1];
}
for (int i = 2;i <= n;i++) {
for (int j = 2;j <= m;j++)
{
dp[i][j] = max(dp[i - 1][j], max(dp[i][j - 1],dp[i-1][j-1]))+map[i][j];
}
}
cout << dp[n][m] << "\n";
return 0;
}