[BOJ] 5557 1학년

Time Lapse :NONE

5557.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <memory.h>

using namespace std;

#define endl '\n'

int N;
unsigned long long dp[101][21];
int arr[101];

unsigned long long func(int idx,int cur)
{
if(cur<0||cur>20)
return 0;

if(idx==0)
{
if(cur==arr[0])
return 1;
else
return 0;
}

unsigned long long &ret = dp[idx][cur];

if(ret!=-1)
return ret;

ret = func(idx-1,cur+arr[idx]) + func(idx-1,cur-arr[idx]);

return ret;
}

int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>N;
for(int i=0;i<N;i++)
cin>>arr[i];

memset(dp,-1,sizeof(dp));

cout<<func(N-2,arr[N-1])<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/5557/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.