Guest User

Count Number of Binary Strings

a guest
Sep 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 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. if(i==n-1)
  9. {
  10. count++;
  11. return;
  12. }
  13. if(arr[i]==0)
  14. {
  15. arr[i+1]=0;
  16. compute(arr,i+1,n);
  17. arr[i+1]=1;
  18. compute(arr,i+1,n);
  19. }
  20. if(arr[i]==1)
  21. {
  22. arr[i+1]=0;
  23. compute(arr,i+1,n);
  24. }
  25. }
  26. int main()
  27. {
  28. int t;
  29. cin>>t;
  30. while(t--)
  31. {
  32. count=0;
  33. //cout<<"Count "<<count<<endl;
  34. int n;
  35. cin>>n;
  36. int arr[n]={0};
  37. compute(arr,0,n);
  38. arr[0]=1;
  39. compute(arr,0,n);
  40. cout<<count<<endl;
  41. }
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment