比赛 2025暑期集训第7场 评测结果 AAAAAAAAAA
题目名称 Power Calculus 最终得分 100
用户昵称 彭欣越 运行时间 4.432 s
代码语言 C++ 内存使用 3.64 MiB
提交时间 2025-08-11 16:17:20
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
int n,dep,t[N];
bool dfs (int idx,int sum) {
	if (idx>dep||sum<<(dep-idx)<n) return false;
	if (sum==n||sum<<(dep-idx)==n) return true;
	t[idx]=sum;
	for (int i=0;i<=idx;i++) {
		if (dfs(idx+1,sum+t[i])) return true;
		if (dfs(idx+1,sum-t[i])) return true;
	}
	return false;
}
int main () {
	freopen("pow_cal.in","r",stdin);
	freopen("pow_cal.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	while (cin >> n&&n) {
		for (dep=0;;dep++) {
			if (dfs(0,1)) {
				cout << dep <<"\n";
				break;
			}
		}
	}
	return 0;
}