[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] LV.2 ๋ฉ€๋ฆฌ ๋›ฐ๊ธฐ (์ž๋ฐ” java)

 

1. ๋ฌธ์ œ : https://school.programmers.co.kr/learn/courses/30/lessons/12914

 

2. ํ’€์ด

dp๋กœ ๋ฐฐ์—ด์— ์ €์žฅํ•˜๋ฉด์„œ ํ’€์–ด์•ผ ํšจ์œจ์ด ๋‚˜์˜ค๋Š” ๋ฌธ์ œ

๊ธฐ๋ณธ ๊ฐœ๋…์€ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด์ด๋‹ค. 

 

3. ์ฝ”๋“œ

class Solution {
  public long solution(int n) {
      int[] dp = new int[2001];
      dp[1] = 1;
      dp[2] = 2;
      for(int i=3; i<2001; i++){
          dp[i] = (dp[i-2] + dp[i-1]) % 1234567;
      }
      return dp[n];
  }
}
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ