ν°μ€ν 리 λ·°
π©π»π» λ¬Έμ
βπ» νμ΄
π¨ Go
// https://www.acmicpc.net/problem/11057
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
fmt.Fprintln(writer, getAscCount(n))
}
func getAscCount(length int) int {
var count int
var dp = make([][]int, length+1) // dp[i][j]: iλ²μ§Έ μ리μμ jκ° μ¬ λμ μ€λ₯΄λ§ μ κ²½μ°μ μ
for i := 0; i < len(dp); i++ {
dp[i] = make([]int, 10)
}
for i := 0; i < 10; i++ {
dp[1][i] = 1 // 1λ²μ§Έ μ리μμ iκ° μ¬ λμ μ€λ₯΄λ§ μ κ²½μ°μ μλ κ°κ° 1μ΄λ€
}
for i := 1; i < length+1; i++ { // dp[i][j] = dp[i-1][0] + dp[i-1][1] + ... + dp[i-1][j]
for j := 0; j < 10; j++ {
for k := 0; k <= j; k++ {
dp[i][j] += dp[i-1][k]
dp[i][j] %= 10007
}
}
}
for i := 0; i < 10; i++ {
count += dp[length][i]
}
return count % 10007
}
π¨ Python3
# https://www.acmicpc.net/problem/11057
import sys
def get_asc_count(n):
count = 0
dp = [[0]*10 for _ in range(n+1)]
for i in range(10):
dp[1][i] = 1
for i in range(1, n+1):
for j in range(10):
for k in range(j+1):
dp[i][j] += dp[i-1][k]
dp[i][j] %= 10007
for i in range(10):
count += dp[n][i]
return count%10007
if __name__ == "__main__":
n = int(sys.stdin.readline())
print(get_asc_count(n))
728x90
'dev > algorithm' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ / 11048λ² / μ΄λνκΈ° [Go][Python3] (0) | 2021.03.26 |
---|---|
BOJ / 1991λ² / νΈλ¦¬ μν [Go][Python3] (0) | 2021.03.25 |
BOJ / 1475λ² / λ°© λ²νΈ [Go][Python3] (0) | 2021.03.23 |
BOJ / 6603λ² / λ‘λ [Go][Python3] (0) | 2021.03.22 |
BOJ / 1182λ² / λΆλΆμμ΄μ ν© [Go][Python3] (0) | 2021.03.21 |
λκΈ
κΈ λ³΄κ΄ν¨
μ΅κ·Όμ λ¬λ¦° λκΈ
TAG
- MongoDB
- BFS
- λ°λ
- μλ°
- λ§₯λΆ μ κ·Έλ μ΄λ
- BOJ
- Golang
- ν΄μ맡
- νλ‘μ΄λμμ¬
- λΆν μ 볡
- μ€ν
- μκ°κ΅μ²΄
- go
- μκ³ λ¦¬μ¦
- dp
- dfs
- λ§₯λΆνλ‘
- λͺ½κ³ λλΉ
- Macbook pro 2012 mid 13
- AWS
- λΈλ£¨νΈν¬μ€
- python3
- μ΄λΆνμ
- λ°±μ€
- ν
- baekjoon
- λ§₯λΆ
- java
- ballet
- Algorithm
- Total
- Today
- Yesterday