怎么不输出
查看原帖
怎么不输出
1048914
cgy20140502楼主2024/12/15 11:39
#include<bits/stdc++.h>
using namespace std;
int a[10001],n;
void print(int t){
	for (int i = 1;i <= t-1;i++) cout << a[i] << "+";
	cout << a[t] << "\n";
}
void dfs(int s,int t){
	int i;
	for (i = a[t-1];i <= s;i++)
		if (i < n){
			a[t] = i;
			s -= i;
			if (s == 0) print(t);
			else dfs(s,t+1);
			s += i;
		}
}
int main(){
	cin >> n;
	dfs(n,1);
	return 0;
}
2024/12/15 11:39
加载中...