-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1757.cpp
More file actions
38 lines (28 loc) · 909 Bytes
/
1757.cpp
File metadata and controls
38 lines (28 loc) · 909 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 10000000
int N,M,D[MAXN];
int opt[10050][550][2];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N >> M;
for(int i=1 ; i<=N ; i++) cin >> D[i];
for(int i=1 ; i<=N ; i++){
for(int j=0 ; j<=M ; j++){
if(j==0){
opt[i][j][0] = max({opt[i-1][j+1][0],opt[i-1][j+1][1],opt[i-1][j][0]});
} else if(j==1){
opt[i][j][0] = max(opt[i-1][j+1][0],opt[i-1][j+1][1]);
opt[i][j][1] = opt[i-1][j-1][0]+D[i]; //max(opt[i-1][j-1][0],opt[i-1][j-1][1])+D[i];
} else {
opt[i][j][0] = max(opt[i-1][j+1][0],opt[i-1][j+1][1]);
opt[i][j][1] = opt[i-1][j-1][1]+D[i];
}
}
}
cout << opt[N][0][0];
}