Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
518 B
4
Indexable
Never
#include<iostream>
using namespace std;
 
int visit[15];
int sum;
int arr[100];
void print(int n){
	for(int i=1; i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;

}
void backtrack(int vt, int sum){
	if(sum>10) return ;
	if(sum==10){
		print(vt); return;
	}
	for(int i=arr[vt-1]+1; i<=10;i++){
		if( !visit[i]){
			visit[i]=1;
			arr[vt]=i;
			backtrack(vt+1,sum+i);
			visit[i]=0;
		}

	}


}
 
int main()
{
	for(int i=0; i<=10;i++){
		visit[i]=0;
	}
backtrack(1,0);
    return 0;
}