Alternate Solution - DP
Explanation
If we define as the minimum number of skip points needed to get to the th boss on player 's turn (our turn is zero), then our transitions would be:
This is because from each state, either the previous move, or the previous two moves could have been from the other player.
So, the answer would be .
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;int main() {int test_case_num;cin >> test_case_num;for (int t = 0; t < test_case_num; t++) {int n;cin >> n;
Java
import java.io.*;import java.util.Arrays;public class MortalKombatTower {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int testCaseNum = Integer.parseInt(br.readLine());for (int t = 0; t < testCaseNum; t++) {int n = Integer.parseInt(br.readLine());
Python
for _ in range(int(input())):n = int(input())bosses = list(map(int, input().split()))# dp[i][j] stores the minimum amount of skip points needed for the j-th# boss when it is your turn (i = 0) and your friend's turn (i = 1).dp = [[float("inf")] * (n + 1) for _ in range(2)]dp[0][0] = 0 # Our friend needs to use zero points to fight no bosses.
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!