// 二分查找+动态规划 classSolution { unordered_map<int, int> memo; intdp(int K, int N){ if (memo.find(N * 100 + K) == memo.end()) { int ans; if (N == 0) ans = 0; elseif (K == 1) ans = N; else { int lo = 1, hi = N; while (lo + 1 < hi) { int x = (lo + hi) / 2; int t1 = dp(K-1, x-1); int t2 = dp(K, N-x);
if (t1 < t2) lo = x; elseif (t1 > t2) hi = x; else lo = hi = x; }