Explanation
First, we binary search on the initial velocity.
Then, we use dynamic programming on bitmasks to check whether an initial velocity is valid. Let be the minimum possible time to reach visit every mice in subset with as the last visited mouse. If it is not possible to reach subset with as the last visited mice, let .
When transitioning, iterate through every mouse not in the current subset and try adding it to the current subset.
Finally, an initial velocity is possible iff there is an index such that .
Implementation
Time Complexity: , where is the maximum possible velocity.
C++
#include <bits/stdc++.h>using namespace std;const int MAX_N = 15;const long double PRECISION = 1e-3, INF = 1e18;long double dp[1 << MAX_N][MAX_N], p[MAX_N]; // p[i] = pow(speed_red, i)struct Mouse {long double x, y, time;
Java
import java.io.*;import java.util.*;public final class CatAndMice {private static final long PRECISION = (long)1e4;public static void main(String[] args) throws IOException {BufferedReader read = new BufferedReader(new InputStreamReader(System.in));int miceNum = Integer.parseInt(read.readLine());int[][] mice = new int[miceNum][];for (int m = 0; m < miceNum; m++) {
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!