USACO Gold 2017 January - Hoof, Paper, Scissors

Author: Neo Wang (C++)

Official Analysis

Solution

The main observation for this problem is to realize that we only need to keep track of the number of games played ii, the number of times switched so far jj, and the current gesture kk in order to determine the most amount of previous games won for any game ii.

For every move, either Bessie can switch to either H, P, S or stay on her current gesture. If she changes her gesture, then the next game i+1i+1 will have used j+1j+1 gestures, which corresponds to the dp\texttt{dp} state dp[i+1][j+1][k]\texttt{dp}[i+1][j+1][k]. We can simulate this for all 3 gestures. Then, we just increment dp[i][j][k]\texttt{dp}[i][j][k] if Bessie wins at game ii with gesture kk.

Note that you can just compare the current gesture to H,P,S because there is always exactly one way to win.

Time Complexity: O(NK)\mathcal{O}(NK)

C++

Implementation

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) begin(x), end(x)

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!