ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ง๐ปโ๐ป ์ฝ๋ฉํ
์คํธ/๋ฐฑ์ค
๋ฐฑ์ค 15624๋ฒ ํผ๋ณด๋์น ์ 7 [Python / JavaScript]
10000COW 2023. 1. 9. 19:27728x90
๋ฐฑ์ค 15624๋ฒ ํผ๋ณด๋์น ์ 7
๋ฌธ์ ์ ํ: DP (๋์ ๊ณํ๋ฒ)
๋ฌธ์ ์ฃผ์ํ ์
Python, JavaScript๋ก ํ์ด์ Top-Down ๋ฐฉ์ ์ฆ, ์ฌ๊ท ๋ฐฉ์์ผ๋ก๋ ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.
๋ํ ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ ์๊ฐ ์ต๋ 100๋ง์ธ๋ฐ, Python์ ์ต๋ 1000๋ฒ๊น์ง ์ฌ๊ทํ ์ ์์ผ๋ฏ๋ก ์ฌ๊ท ๋ฐฉ์์ผ๋ก๋ ํ๋ฆฌ์ง ์๋๋ค.
๋ฐ๋ผ์ ์ด ๋ฌธ์ ๋ ๋ฉ๋ชจ์ด์ ์ด์ + Bottom-Up ๋ฐฉ์์ผ๋ก ํ์ดํ๋ค.
Python ์ฝ๋
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputN = int(input()) | |
pivoDict = {0:0, 1:1} | |
def pivo(idx): | |
if idx in pivoDict: | |
return pivoDict[idx] | |
for n in range(2, idx+1): | |
pivoDict[n] = ((pivo(n-1) % 1000000007) + (pivo(n-2) % 1000000007)) % 1000000007 | |
return pivoDict[idx] | |
print(pivo(inputN)) |
JavaScript ์ฝ๋
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pivoDict = {0:0, 1:1} | |
function pivo(idx){ | |
if(idx in pivoDict){ | |
return pivoDict[idx] | |
} | |
else{ | |
for(let n=2; n<idx+1; n++){ | |
pivoDict[n] = ((pivo(n-1)%1000000007) + (pivo(n-2) % 1000000007)) % 1000000007 | |
} | |
return pivoDict[idx] | |
} | |
} | |
console.log(pivo(1000)) |
728x90
'๐ง๐ปโ๐ป ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Greedy] 2212 ์ผ์(Python) (0) | 2023.02.20 |
---|---|
๋ฐฑ์ค 1966๋ฒ ํ๋ฆฐํฐํ [์๋ฎฌ๋ ์ด์ ][Python] (1) | 2023.01.17 |
ํ ์ด๋ ์ดํดํ๋ ๋ฐฑ์ค 9251๋ฒ LCS [DP][Python] (2) | 2023.01.15 |
๋ฐฑ์ค 1912๋ฒ ๋์ ํฉ [DP][Python] (0) | 2023.01.14 |
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ์๋ฃ๊ตฌ์กฐ
- Component
- github
- DOM
- zustand
- git
- leetcode
- BOJ
- React Query
- JavaScript
- ์ ๋ ฌ
- state
- ํจ์
- ์๋ฐ์คํฌ๋ฆฝํธ
- ํ์ด์ฌ
- useState
- Browser
- mdn
- DB
- react
- ์๊ณ ๋ฆฌ์ฆ
- ๋ธ๋ผ์ฐ์
- Context API
- ๋ฆฌ์กํธ
- CSS
- ๊ทธ๋ํ
- Python
- error
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์๋ฌ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ
250x250