http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1168
当时以为这题过的了,一直在做这题,才发现后面有两道水题,
然后时间过了很久,所以很慌张,搞的a了很久,最后搞出来了。
这题题意是alice 可以拿2^xi 个stone bob 可以拿 3^yi 个 stone , alice first ,然后刚好拿完N个stone的最小次数。
开始T case, T 个n;
#include <cstdio>
#include <cstring>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int N, f[2][10005];
int a[2] = {2, 3};
const int inf = 0x3fffffff;
int dfs(int x, int m) { // x=0表示Alice走,x=1表示Bob走
if (~f[x][m]) return f[x][m]; // 如果该状态已经搜索过
int t = m, c = 1, Min = inf;
while (t - c >= 0) {
Min = min(Min, dfs(!x, t-c)+1);
c *= a[x];
}
return f[x][m] = Min;
}
int main() {
int T;
scanf("%d", &T);
memset(f, 0xff, sizeof (f));
f[1][0] = f[0][0] = 0; // 边界条件
while (T--) {
scanf("%d", &N);
printf("%d\n", dfs(0, N));
}
return 0;
}