-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11048.cpp
More file actions
48 lines (42 loc) · 1.13 KB
/
11048.cpp
File metadata and controls
48 lines (42 loc) · 1.13 KB
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
#include <iostream>
#include <math.h>
#include <algorithm>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
int arr[1001][1001] ;
int dp[1001][1001] ;
int max_triple(int &a, int &b, int &c)
{
return max(a, max(b, c)) ;
}
int main()
{
SETTING ;
int N, M ;
cin >> N >> M ;
for(int i = 1 ; i <= N ; i++)
for(int j = 1 ; j <= M ; j++)
cin >> arr[i][j] ;
for(int i = 1 ; i <= N ; i++)
for(int j = 1 ; j <= M ; j++)
dp[i][j] = max_triple(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + arr[i][j] ;
cout << dp[N][M] << "\n" ;
}
#include <cstdio>
#include <unistd.h>
#define max(x, y) (x > y ? x : y)
int main() {
char r[1 << 16], *p = r; read(0, r, 1 << 16);
auto ReadInt = [&]() {
int n = 0;
while (1) {
if (p - r == 1 << 16) read(0, p = r, 1 << 16);
if (~*p & 16) break;
n = 10 * n + (*p++ & 15);
}
return p++, n;
};
int n = ReadInt(), m = ReadInt(), DP[1001]{};
while (n--) for (int i = 1; i <= m; i++) DP[i] = max(DP[i - 1], DP[i]) + ReadInt();
printf("%d\n", DP[m]);
}