Problem


Logic

분석

  • 문제 유형 (알고리즘…)
  • 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도…)

설계

  1. 알고리즘 선택
  2. 자료구조 선택
  3. 수도 코드 작성
  4. 정합판단
  • 1 ~ 3과정으로 도출된 로직이 문제를 해결하는가
    • 그렇다 구현
    • 잘 모르겠다 구현
    • 아니다 1번부터 다시 점검

구현

  • 로직 검증

테스트

  • 예외 케이스 고려

My Code

cpp

boj/1003.cpp
// https://www.acmicpc.net/problem/1003
// https://codeyoma.github.io/Computer-Science/1-Foundations--and--Theory/Algorithms/ps/boj/1003/1003
#include <iostream>
using namespace std;
 
#ifdef LOCAL
#    define LOG clog
#else
struct nullstream : ostream {
    nullstream()
        : ostream(nullptr) {}
};
nullstream LOG;
#endif
 
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
 
//--------------------------------------------------------------------------------------------------
 
#define MAX (1234567891)
#define MIN (-1234567891)
 
#include <iostream>
#include <vector>
 
struct base {
    int zero_count;
    int one_count;
};
 
int main() {
    fast_io();
 
    //   logic
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
 
        vector<base> dp(n + 1);
        dp[0] = { 1, 0 };
        dp[1] = { 0, 1 };
 
        if (n >= 2) {
            dp[2] = { 1, 1 };
 
            for (int i = 3; i <= n; ++i) {
                dp[i] = { dp[i - 1].zero_count + dp[i - 2].zero_count,
                          dp[i - 1].one_count + dp[i - 2].one_count };
            }
        }
 
        cout << dp[n].zero_count << " " << dp[n].one_count << "\n";
    }
}