BAEKJOON : 1149, 1309, 11057
No. 1149
1. Problem
2. My Solution
# dp[i][j] -> i = n, j = color (R = 0, G = 1, B = 2)
import sys
n = int(sys.stdin.readline().rstrip())
dp = [[0,0,0] for _ in range(n+1)]
color_cost =[[0,0,0]]
for _ in range(n):
color_cost.append(list(map(int,sys.stdin.readline().rstrip().split())))
for i in range(3):
dp[1][i] = color_cost[1][i]
for i in range(1,n+1):
dp[i][0] = min(dp[i-1][1]+color_cost[i][0],dp[i-1][2]+color_cost[i][0])
dp[i][1] = min(dp[i-1][0]+color_cost[i][1],dp[i-1][2]+color_cost[i][1])
dp[i][2] = min(dp[i-1][0]+color_cost[i][2],dp[i-1][1]+color_cost[i][2])
print(min(dp[n]))
No. 1309
1. Problem
2. Others' Solutions
# dp[i][j] -> i = n, j = 사자의 위치 (0 = 없음, 1 = 왼쪽, 2 = 오른쪽)
import sys
n = int(sys.stdin.readline().rstrip())
dp = [[0,0,0] for _ in range(100001)]
for i in range(3):
dp[1][i] = 1
for i in range(2,100001):
dp[i][0] = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2]) % 9901
dp[i][1] = (dp[i-1][0] + dp[i-1][2]) % 9901
dp[i][2] = (dp[i-1][0] + dp[i-1][1]) % 9901
print(sum(dp[n]) % 9901)
3. Learned No. 11057
1. Problem
2. My Solution
dp[i][j]は、上り坂数の長さとjがどのように終わるかに関する情報を含む.
import sys
n = int(sys.stdin.readline().rstrip())
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] % 10007
print(sum(dp[n]) % 10007)
Reference
この問題について(BAEKJOON : 1149, 1309, 11057), 我々は、より多くの情報をここで見つけました https://velog.io/@codren/BAEKJOON-1149テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol