Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 2193 - 이친수

JaykayChoi 2016. 12. 25. 16:39

문제: https://www.acmicpc.net/problem/2193


dynamic programming 방법 중 하나인 memoization 으로 쉽게 풀 수 있는 문제입니다. 

우선 이친수를 구할 수 있는 재귀함수를 만들고 memoization 을 사용하는 방법으로 풀었습니다.



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
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
 
using namespace std;
typedef long long ll;
 
ll cache[91][2];
ll getPinaryNumber(int digit, int num)
{
    if (digit == 1)
        return 1;
 
    ll& ret = cache[digit][num];
    if (ret != 0)
        return ret;
 
    if (num == 1)
        ret += getPinaryNumber(digit - 10);
    else
        ret += getPinaryNumber(digit - 11+ getPinaryNumber(digit - 10);
 
    return ret;
}
 
int main()
{        
    int digit;
    cin >> digit;
    memset(cache, 0sizeof(cache));
    cout << getPinaryNumber(digit, 1<< endl;
 
    return 0;
}
cs


'Algorithm, Data structure > Solved Algorithmic Problem' 카테고리의 다른 글

BAEKJOON 10815 - 숫자 카드  (0) 2016.12.26
BAEKJOON 1920 - 수 찾기  (0) 2016.12.25
BAEKJOON 1629 - 곱셈  (0) 2016.12.24
BAEKJOON 2703 - Cryptoquote  (0) 2016.12.22
BAEKJOON 2702 - Sixth Grade Math  (0) 2016.12.22