这题怎么递归,思路不太清楚
查看原帖
这题怎么递归,思路不太清楚
714382
bing_wang_zhi_xia楼主2023/6/15 17:37
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s=0,a[6000][10];
	cin>>n;
	if(n>30||n<10){
		cout<<0;
	}else{
		for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
		    for(int k=1;k<=3;k++){
		        for(int l=1;i<=3;l++){
		            for(int m=1;m<=3;m++){
		                for(int o=1;o<=3;o++){
		                    for(int u=1;u<=3;u++){
		                        for(int y=1;y<=3;y++){
		                        	for(int t=1;t<=3;t++){
		                        		for(int r=1;r<=3;r++){
		                        			if(i+j+k+l+m+o+u+y+t+r==n){
												a[0][s]=i;
												a[1][s]=j;
												a[2][s]=k;
												a[3][s]=l;
												a[4][s]=m;
												a[5][s]=o;
												a[6][s]=u;
												a[7][s]=y;
												a[8][s]=t;
												a[9][s]=r;
												s++;
											}
									    }
									}
	        					}
	    					}
	                	}
	            	}
	            }
	        }
	    }
	}
	cout<<s;
		for(int i=0;i<s;i++){
			for(int j=0;j<10;j++){
				cout<<a[i][j];
			}
		}
	}
	return 0;
} 
2023/6/15 17:37
加载中...