-
Notifications
You must be signed in to change notification settings - Fork 14
/
Corona Virus.cpp
49 lines (39 loc) · 929 Bytes
/
Corona Virus.cpp
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
41
42
43
44
45
46
47
48
49
// BY AYUSH AKASH
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int length;
string S;
cin >> length >> S;
const int MOD = 1e9 + 7;
vector <long long> no_of_ways(length + 1);
for(int i = 0; i < length; i++)
{
int ones_here = 0;
for(int j = i; j >= 0 && ones_here <= 2; j--)
{
ones_here += (S[j] == '1');
if(ones_here == 2)
{
if(j >= 1)
{
no_of_ways[i] += no_of_ways[j - 1];
}
else
{
no_of_ways[i]++;
}
}
}
no_of_ways[i] %= MOD;
}
long long answer = no_of_ways[length - 1];
if(no_of_ways[length - 1] == 0)
{
answer = -1;
}
cout << answer << "\n";
return 0;
}