tungggg

Backtrack_BinaryString

Feb 7th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int n;
  4. int a[100];
  5. void show(){
  6. for(int i=1;i<=n;i++){
  7. cout<<a[i];
  8. }
  9. }
  10. void backtrack (int pos){
  11. if (pos==n+1){
  12. show();
  13. cout<<endl;
  14. return ;
  15. }
  16. else {
  17. for(int i=0;i<=1;i++){
  18. // cac gia tri co trong tap hoan vi
  19. a[pos]=i;
  20. backtrack(pos+1);
  21. }
  22. }
  23. }
  24. int main(){
  25. cin>>n;
  26. backtrack(1);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment