Untitled
unknown
plain_text
a month ago
968 B
5
Indexable
#include<bits/stdc++.h> using namespace std; int n; int arr[8]; int seen[8]; int mande; bool flagmande = 0; int mx; void jaygasht(int ind){ if(ind == n){ for(int i = 0; i<n; i++){ cout << arr[i] << " "; } cout << endl; return; } for(int i = 0; i<mx; i++){ if(seen[i] == 0){ arr[ind] = i+1; seen[i] += 1; jaygasht(ind+1); arr[ind] = 0; seen[i] --; } } } void b_fasele(int ind){ if(ind == n){ for(int i = 0; i<n; i++){ cout << arr[i] << " "; } cout << endl; return; } if(mande == n){ jaygasht(ind); } else{ for(int i = 0; i<mx; i++){ arr[ind] = i+1; if(seen[i] == 0){ mande--; flagmande = 1; } seen[i]++; b_fasele(ind+1); arr[ind] = 0; if(flagmande){ mande++; flagmande = 0; } seen[i]--; } } } int main(){ cin >> n; for(int i = 0; i<n; i++){ mande = i+1; mx = i+1; b_fasele(0); } }
Editor is loading...
Leave a Comment