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]))
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
1. Problem
2. My Solution
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)