2013湘大邀請賽a題

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;
}


發佈了19 篇原創文章 · 獲贊 9 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章