8000 Create 2579_2.cpp · rinrin528/basic-algo-lecture@20c8d31 · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit 20c8d31

Browse files
Create 2579_2.cpp
1 parent cc4ebf8 commit 20c8d31

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

0x10/2579_2.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// http://boj.kr/e93e56bb850a46378cf8f53486233cdc
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int s[305];
6+
int n;
7+
int d[305];
8+
9+
int main(void){
10+
ios::sync_with_stdio(0);
11+
cin.tie(0);
12+
cin >> n;
13+
int tot = 0;
14+
for(int i = 1; i <= n; i++){
15+
cin >> s[i];
16+
tot += s[i];
17+
}
18+
if(n <= 2){
19+
cout << tot;
20+
return 0;
21+
}
22+
d[1] = s[1];
23+
d[2] = s[2];
24+
d[3] = s[3];
25+
for(int i = 4; i <= n-1; i++) d[i] = min(d[i-2],d[i-3])+s[i];
26+
cout << tot - min(d[n-1],d[n-2]);
27+
}

0 commit comments

Comments
 (0)
0