[BOJ] 2193 이친수

Time Lapse :NONE

2193.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
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <memory.h>

using namespace std;

#define MAXSIZE 100
long long dp[MAXSIZE][2];
int n;
long long ans=0;

long long func(int idx,int prev)
{
if(idx==n)
return 1;

long long &ret = dp[idx][prev];
if(ret!=-1)
return ret;

if(prev==1)
{
ret = func(idx+1,0);
}
else
ret = func(idx+1,1) + func(idx+1,0);

return ret;
}

int main(void)
{
cin>>n;
memset(dp,-1,sizeof(dp));
ans = func(1,1);
cout<<ans<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2193/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.