rohan02

Untitled

Sep 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int count=0;
  5.  
  6.  
  7. void countsubstring(int arr[],int i ,int n)
  8. {
  9.  
  10. if(i==n-1)
  11. {
  12. count++;
  13.  
  14. return;
  15. }
  16.  
  17.  
  18. if(arr[i]==1)
  19. {
  20. arr[i+1]=0;
  21. countsubstring(arr,i+1,n);
  22. return;
  23. }
  24. else
  25. {
  26. arr[i+1]=0;
  27. countsubstring(arr,i+1,n);
  28. arr[i+1]=1;
  29. countsubstring(arr,i+1,n);
  30. return;
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41. int t;
  42. cin>>t;
  43. while(t--)
  44. {
  45. int n;
  46. cin>>n;
  47. int arr[n];
  48.  
  49. count=0;
  50.  
  51. arr[0]=1;
  52. countsubstring(arr,0,n);
  53.  
  54. arr[0]=0;
  55. countsubstring(arr,0,n);
  56.  
  57. cout<<count<<endl;
  58.  
  59.  
  60.  
  61.  
  62. }
  63.  
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment