Description
For a sequence a_1, a_2, \ldots, a_na1,a2,…,an, consider the following operation ff: f(a)={b_1, b_2, \ldots, b{n-1}}f(a)=b1,b2,…,bn−1, where b_i=|a_i-a{i+1}|bi=∣ai−ai+1∣.
After applying the operation ff for n-1n−1 times, denoted by f^{n-1}(a)fn−1(a), the sequence will become a single element.
Bobo has a sequence aa of length nn filled with0
,1
and?
. He would like to know the number of ways modulo (10^9+7)(109+7) to replace?
to0
or1
such that f^{n-1}(a)={1}fn−1(a)=1.
Input
The input consists of several test cases terminated by end-of-file. For each test case:
The first line contains a nonempty string aa consisting only of0
,1
and?
, denoting the given sequence.
-
1 \leq |a| \leq 10^61≤∣a∣≤106
-
The sum of |a|∣a∣ does not exceed 10^7107.
Output
For each test case, print an integer which denotes the result.
sample input1:1
sample output1:1
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define ll long long
ll pow_(ll a,ll b){
ll an=1;
while(b){
if(b&1)
an=an*a%mod;
b/=2;
a=a*a%mod;
}
return an;
}
char s[1000005];
int main(){
while(~scanf("%s",s+1)){
int ls=strlen(s+1);
int c1=0,c2=0,c3=0,c4=0;
for(int i=1;i<=ls;++i)
if(s[i]=='?'&&((ls-1)&(i-1))==i-1)++c1;
else if(s[i]=='?')++c2;
else if(s[i]=='1'&&((ls-1)&(i-1))==i-1)++c3;
c3%=2;
if(c3==0&&c1==0)
printf("0\n");
else if(c1==0)
printf("%lld\n",pow_(2,c2));
else printf("%lld\n",pow_(2,c1+c2-1));
}
}
多多支持博主,谢谢各位!!!