티스토리 뷰

https://www.acmicpc.net/problem/26529

 

26529번: Bunnies

You’re going to raise farm animals and you decided to start with bunnies, the easiest of animals. To your surprise they are breeding like rabbits, so much so that you’re unable to count them accurately. However, you know that rabbits’ breeding patter

www.acmicpc.net

 

dp[i]는 i달 후 토끼의 수

조건식
dp[i] = dp[i-1]+ dp[i-1] (i>1);

초기값
dp[0] = 1;
dp[1] = 1;

 

 

const input = require('fs').readFileSync('./dev/stdin').toString().trim().split('\n').map(Number);
const N = input.shift();

let dp = Array(46).fill(1);

for (let i = 2; i <= 45; i++) {
	dp[i] = dp[i - 1] + dp[i - 2];
}

const answer = [];
for (let i = 0; i < N; i++) {
	const h = input[i];
	answer.push(dp[h]);
}

console.log(answer.join('\n'));
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함