Logo냥냠감자기술 블로그
Skip to Content
AlgorithmDP (31)1, 2, 3 더하기 3
작성일: 2024-01-18

문제

백준 15988 - 1, 2, 3 더하기 3 

  • 난이도: 실버2
  • 알고리즘: dp

코드

#include <iostream> #include <vector> using namespace std; vector<int> cache(1000001, -1); int getCaseNum(int input) { if(input<0) return 0; if(input==0) return 1; if(cache[input]!=-1) return cache[input]; cache[input]=0; for(int i=1; i<=3; i++) { cache[input]+=getCaseNum(input-i); cache[input]%=1000000009; } return cache[input]; } int main() { int testCase; cin>>testCase; for(; testCase>0; testCase--) { int input; cin>>input; cout<<getCaseNum(input)<<"\n"; } }

회고

요즘 매일 비슷한 문제만 풀고 있는거 같은데 이제는 너무 쉽게 풀린다. 코드 짜는데 1분 정도 걸린거 같다.