[BOJ] 1904 01타일

Time Lapse :NONE

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

using namespace std;

#define MAXSIZE 1000001
long long cache[MAXSIZE];
int n;
long long ans = 0;

long long dp(int num)
{
int ret = cache[num];
if (ret != -1)
return ret;

ret = dp(num - 1) + dp(num - 2);
return ret;
}
int main(void)
{
cin >> n;
memset(cache, -1, sizeof(cache));
cache[0] = 1;
cache[1] = 1;
for (int i = 2; i <= n; i++)
cache[i] = (cache[i - 2] + cache[i - 1])%15746;
//ans = cache[i]
cout << cache[n] << endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1904/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.