ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 BOJ 12849 본대산책
    Problem Solving/BOJ 2021. 1. 2. 19:57

    예전에 어떤 알파벳은 특정 알파벳 다음에만 올 수 있다는 규칙의 문제와 같다

     (ex u는 e,i,o 다음에 올 수있고 e 는 a,u,o 다음에 올 수있고..)

     

    특정시점의 어느 위치는 그 바로 이전의 연결된 위치에서만 올 수 있다

     

    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
    48
    49
    50
    51
    #include<iostream>
    #include<memory.h>
    #include<vector>
    #include<queue>
    #include<unordered_map>
    #include<algorithm>
    #include<string>
    #include<cmath>
    #define INF 1e9
    #define MOD 1000000007
    using namespace std;
    using lld = long long int;
    using pii = pair<intint>;
    int n, m, k;
     
    int dp[8][100001];
    int pre[8][4= {
        {1,2,-1,-1},
        {0,2,3,-1},
        {0,1,3,4},
        {1,2,4,5},
        {2,3,5,6},
        {3,4,7,-1},
        {4,7,-1,-1},
        {5,6,-1,-1}};
     
    int main() {
    //    ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
        
        scanf("%d",&n);
        
        memset(dp,0,sizeof(dp));
        
        dp[1][1]=1;
        dp[2][1]=1;
        for(int i=2;i<=100001;i++){
            for(int j=0;j<8;j++){
                for(int k=0;k<4;k++){
                    if(pre[j][k] == -1continue;
                    dp[j][i] = (dp[pre[j][k]][i-1+ dp[j][i]) %MOD;
                }
            }
        }
        
        printf("%d\n",dp[0][n]);
        
        
        return 0;
    }
     
    cs

    'Problem Solving > BOJ' 카테고리의 다른 글

    LIS (Longest Increasing Subsequence)  (0) 2023.06.17
    백준 BOJ 11025 요세푸스 문제 3  (1) 2023.01.22
    백준 BOJ 2473 세 용액  (0) 2020.12.31
    백준 BOJ 2568 - 전깃줄-2  (0) 2020.12.31
    백준 BOJ 14725 개미굴  (0) 2020.12.29
Designed by Tistory.