ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/9184
package main
import (
"bufio"
"fmt"
"os"
)
var (
dp [][][]int
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
for {
var a, b, c int
fmt.Fscanln(reader, &a, &b, &c)
if a == -1 && b == -1 && c == -1 {
break
}
dp = make([][][]int, 21)
for i := 0; i < 21; i++ {
dp[i] = make([][]int, 21)
for j := 0; j < 21; j++ {
dp[i][j] = make([]int, 21)
}
}
fmt.Fprintf(writer, "w(%d, %d, %d) = %d\n", a, b, c, w(a, b, c))
}
}
func w(a, b, c int) int {
if a <= 0 || b <= 0 || c <= 0 {
return 1
}
if a > 20 || b > 20 || c > 20 {
return w(20, 20, 20)
}
if dp[a][b][c] != 0 {
return dp[a][b][c]
}
if a < b && b < c {
dp[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
} else {
dp[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
}
return dp[a][b][c]
}
๐จ Python3
# https://www.acmicpc.net/problem/9184
import sys
dp = [[[0 for i in range(21)] for j in range(21)] for k in range(21)]
def w(a, b, c):
if a <= 0 or b <= 0 or c <= 0:
return 1
if a > 20 or b > 20 or c > 20:
return w(20, 20, 20)
if dp[a][b][c] != 0:
return dp[a][b][c]
if a < b and b < c:
dp[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)
else:
dp[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)
return dp[a][b][c]
if __name__ == "__main__":
while True:
a, b, c = list(map(int, sys.stdin.readline().split()))
if a == -1 and b == -1 and c == -1:
break
print("w({}, {}, {}) = {}".format(a, b, c, w(a, b, c)))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 13699๋ฒ / ์ ํ์ [Go][Python3] (0) | 2021.03.07 |
---|---|
BOJ / 16395๋ฒ / ํ์ค์นผ์ ์ผ๊ฐํ [Go][Python3] (0) | 2021.03.06 |
BOJ / 1292๋ฒ / ์ฝ๊ฒ ํธ๋ ๋ฌธ์ [Go][Python3] (0) | 2021.03.04 |
BOJ / 1026๋ฒ / ๋ณด๋ฌผ [Go][Python3] (0) | 2021.03.03 |
BOJ / 13305๋ฒ / ์ฃผ์ ์ [Go][Python3] (0) | 2021.03.02 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- dfs
- ballet
- ๋ชฝ๊ณ ๋๋น
- BFS
- Macbook pro 2012 mid 13
- java
- ์๋ฐ
- dp
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- BOJ
- ํ๋ก์ด๋์์ฌ
- go
- python3
- ์คํ
- MongoDB
- ๋ธ๋ฃจํธํฌ์ค
- ์ด๋ถํ์
- ์๊ณ ๋ฆฌ์ฆ
- ํด์๋งต
- Golang
- ๋ถํ ์ ๋ณต
- ํ
- AWS
- ์๊ฐ๊ต์ฒด
- ๋ฐฑ์ค
- baekjoon
- ๋งฅ๋ถํ๋ก
- ๋งฅ๋ถ
- Algorithm
- ๋ฐ๋
- Total
- Today
- Yesterday