首页 > 技术文章 > [HNOI2006]鬼谷子的钱袋

sdfzhsz 2018-10-19 15:31 原文

发现如果要凑\(n\)的钱,如果凑齐了\(\ulcorner n/2 \urcorner\)以下钱再来一个\(\llcorner n/2 \lrcorner\)就行了。
这样我们就可以分治了。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long m;
int tot;
void print(long long now) {
	if(!now) {printf("%d\n",tot);return;}
	tot++;
	print(now>>1);
	printf("%lld ",(now+1)>>1);
}
int main() {
	cin>>m;
	print(m);
	return 0;
}

推荐阅读