Blog

ETC

Published 1 min read

Setting up the recurrence is essential for every problem

Problem 2225: Sum Decomposition

Problem 5557: First Grade

Problem 15486: Resignation 2

Problem 2240: Plum Tree

Problem 2096: Going Down

Problem 13398: Consecutive Sum 2

Problem 11058: Kriii Board

Problem 2666: Moving Closet Doors

Problem 14567: Prerequisite

Problem 2229: Making Teams

Problem 2410: Sum of Powers of 2

Ezreal goes mid first gg - 20500

Problem 20500: Ezreal goes mid first gg

You can store the number itself instead of the remainder.
But it's probably better to solve it by storing the remainder.
Handling the inverse operation of the remainder can be important in this problem.

let FIVE = 1, ONE = 0, MOD = 1_000_000_007 let N = Int(readLine()!)! var dp = [[[Int]]](repeating:[[Int]](repeating:[Int](repeating:0,count:2),count:3),count:N+1) dp[1][1][ONE] = 1 dp[1][2][FIVE] = 1 for i in 1..<N { for j in 0...2 { dp[i+1][(j+1)%3][ONE] = (dp[i+1][(j+1)%3][ONE] + dp[i][j][ONE]) % MOD dp[i+1][(j+1)%3][ONE] = (dp[i+1][(j+1)%3][ONE] + dp[i][j][FIVE]) % MOD dp[i+1][(j+5)%3][FIVE] = (dp[i+1][(j+5)%3][FIVE] + dp[i][j][ONE]) % MOD dp[i+1][(j+5)%3][FIVE] = (dp[i+1][(j+5)%3][FIVE] + dp[i][j][FIVE]) % MOD } } print(dp[N][0][FIVE])

Problem 16500: String Check

Problem 1915: Largest Square

Comments

Leaving a comment stores your nickname (or GitHub profile info). Privacy policy

GitHub