| 比赛 | 
    EYOI暨SBOI暑假快乐赛2nd | 
    评测结果 | 
    AAAAAAAAAA | 
    | 题目名称 | 
    幂次计算 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    cb | 
    运行时间 | 
    2.684 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    1.70 MiB  | 
    | 提交时间 | 
    2022-06-26 11:19:20 | 
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1010;
int a[MAXN];
int n ,depth = 0;
bool iddfs (int x ,int cur) {
	if (x << (depth - cur) < n) return false;
	if (cur > depth) return false;
	a[cur] = x;
	if (x == n) return true;
	for (int q = 0;q <= cur;++ q) {
		if (iddfs (x + a[q] ,cur + 1)) { return true; }
		if (iddfs (x > a[q] ? x - a[q] : a[q] - x ,cur + 1)) { return true;}
	}
	return false;
}
int main () {
	freopen("mico.in","r",stdin);
	freopen("mico.out","w",stdout);
	while (scanf("%d",&n) && n) {
		depth = 0;
		memset (a ,0 ,sizeof (a));
		while (!iddfs (1 ,0)) {
			memset (a ,0 ,sizeof (a));
			depth ++; }
		printf ("%d\n",depth);
	}
	return 0;
}