-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignManu.cpp
More file actions
40 lines (31 loc) · 800 Bytes
/
AssignManu.cpp
File metadata and controls
40 lines (31 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define M 1000000007
map<ll,ll> mp;
// function to calculate no. of strings such that there are no consecutive 0's
ll total_no_of_strings(ll n)
{
// Base cases
if (mp.count(n)) return mp[n];
ll k=n/2;
if (n%2==0) { // n=2*k
return mp[n] = (total_no_of_strings(k)*total_no_of_strings(k) + total_no_of_strings(k-1)*total_no_of_strings(k-1)) % M;
} else { // n=2*k+1
return mp[n] = (total_no_of_strings(k)*total_no_of_strings(k+1) + total_no_of_strings(k-1)*total_no_of_strings(k)) % M;
}
}
//Main Function
int main()
{
int t;
cin>>t;
mp[0]=mp[1]=1;
while(t--)
{
ll n;
cin>>n;
cout<<total_no_of_strings(n+1)<<endl;//no. of strings such that there are no consecutive 0's
}
return 0;
}