[BOJ] 11052 카드 구매하기

Time Lapse :25min 25sec

11052.cpp

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
#include <iostream>
#include <memory.h>
#include <algorithm>
using namespace std;
int N;
int cards[1001];
int DP[1001];

int func(int n){
int &ret = DP[n];
if(ret!=-1)
return ret;
ret = cards[n];
for(int i=1;i<=n/2;i++){
ret = max(ret,func(i)+func(n-i));
}
return ret;
}

int main(void){
int N;
cin>>N;
for(int i=1;i<=N;i++)
cin>>cards[i];
memset(DP,-1,sizeof(DP));
DP[0] = cards[0] = 0;
DP[1] = cards[1];
func(N);
cout<<DP[N]<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11052/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.