Guest User

Untitled

a guest
Sep 15th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. static long long int count =0;
  5.  
  6. void compute(int arr[],int i,int n)
  7. {
  8. // Base case
  9. if(i==n-1)
  10. {
  11. count++;
  12. return;
  13. }
  14.  
  15. // When the binary string is starting with 0
  16. if(arr[i]==0)
  17. {
  18. arr[i+1]=0;
  19. compute(arr,i+1,n);
  20. arr[i+1]=1;
  21. compute(arr,i+1,n);
  22. }
  23.  
  24. // When the binary string is starting with 1
  25. if(arr[i]==1)
  26. {
  27. arr[i+1]=0;
  28. compute(arr,i+1,n);
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. int t;
  35. cin>>t;
  36. while(t--)
  37. {
  38. count=0;
  39. //cout<<"Count "<<count<<endl;
  40. int n;
  41. cin>>n;
  42. int arr[n]={0};
  43. compute(arr,0,n);
  44. arr[0]=1;
  45. compute(arr,0,n);
  46. cout<<count<<endl;
  47. }
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment