[BOJ] 1932 정수 삼각형

Time Lapse :4min 49sec

1932.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>
using namespace std;
int DP[500][500];
int triangle[500][500];
int N;

int func(int x,int y){
if(y==N-1){
return triangle[y][x];
}
int &ret = DP[y][x];
if(ret!=-1)
return ret;
ret = triangle[y][x];
ret += max(func(x,y+1),func(x+1,y+1));
return ret;
}

int main(void){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<=i;j++){
cin>>triangle[i][j];
}
}
memset(DP,-1,sizeof(DP));
cout<<func(0,0)<<endl;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1932/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.