大佬求调
查看原帖
大佬求调
1390696
Caolei1126楼主2025/1/11 16:09

大佬求调

#include <bits/stdc++.h>
using namespace std;

long long n, a[1140014] = {1};

void dfs(int x, int z) {
	for (int i = a[x - 1]; i <= z; i++) {
		if (i < n) {
			a[x] = i;
			z -= i;
		}
		if (!z) {
			cout << a[1];
			for (int j = 2; j <= x; j++) {
				cout << "+" << a[j];
			}
			cout << endl;
			return;
		} else {
			dfs(x + 1, z), z += i;
		}
	}
}

int main() {
	cin >> n;
	dfs(1, n);
	return 0;
}

2025/1/11 16:09
加载中...