P2089烤鸡c++dfs玄关求调
  • 板块灌水区
  • 楼主Tennantloyaldog
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/5/25 20:18
  • 上次更新2024/5/25 22:08:11
查看原帖
P2089烤鸡c++dfs玄关求调
1042335
Tennantloyaldog楼主2024/5/25 20:18

题目传送门

#include<bits/stdc++.h>
using namespace std;
int cnt,n;
int a[10];
int b[100010][10];
void dfs(int k,int sum){
	if(k==11){
		if(sum==n){
			cnt++;
			for(int j=0;j<10;j++){
				b[cnt][j]=a[j];
			}
		}
		return;
	}
	for(int i=1;i<4;i++){
		if(sum+i>n)return;
		a[k]=i;
		dfs(k+1,sum+i);
	}	
}
int main(){
	cin >> n;
	dfs(1,0);
	cout << cnt<<"\n";
	for(int i=0;i<cnt;i++){
		for(int j=0;j<10;j++){
			cout << b[i][j]<<" ";
		}
		cout <<"\n";
	}
	return 0;
}
2024/5/25 20:18
加载中...