80分求调
查看原帖
80分求调
1046231
Farmer___John楼主2025/7/31 19:49
#include<bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
long long n, ans, cnt, a[N], c[N][15], t, m, k, s;
void f(){
	long long ans = 0;
	for(int i = 1; i <= 10; i++)
		ans += a[i];
	if(ans == n){
		cnt++;
		for(int i = 1; i <= 10; i++)
			c[cnt][i] = a[i];
	}
}
void l(int x, int s){
	if(x > 10){
		f();
		return ;
	}
	for(int j = 1; j <= 3; j++){
		if(j <= s){
			a[x] = j;
			l(x + 1, s - j);
		}
	}
} 
int main(){
	cin >> n;
	if(n < 10 || n > 30){
		cout << 0;
		return 0;
	}
	l(1, n);
	cout << cnt << endl;
	for(int i = 1; i <= cnt; i++){
		for(int j = 1; j <= 10; j++)
			cout << c[i][j] << " ";
		cout << endl; 
	}
	return 0;
}
2025/7/31 19:49
加载中...