You are given a positive integer in base two.How many pairs of non-negative integers
satisfy the following conditions?
Since there can be extremely many such pairs, print the count modulo .
首先假设 全是
的时候,按相同长度来考虑,根据题意,如果
的第
位是
则
的第
位必须是
.
所以答案就是 .
算一般情况时,统计 的前
位有
个
,后面
位答案就是
,前
位的有
种情况,所以答案就是
,累加起来就好.
#include<bits/stdc++.h> #define me(a,x) memset(a,x,sizeof(a)) #define sc scanf #define itn int using namespace std; const int N=2e5+5; const long long mod=1e9+7; const int oo=0x7fffffff; const int sup=0x80000000; typedef long long ll; typedef unsigned long long ull; template <typename it> string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;} template <typename it>int o(it a){cout<<a<<endl;return 0;} char s[N]; int main(){ cin>>(s+1); auto ksm=[](ll a,ll b){ ll ans=1; for(;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod; return ans; }; int n=strlen(s+1); ll ans=0; int cnt=0; for(int i=1;i<=n;i++){ if(s[i]=='1'){ ans=(ans+ksm(2,cnt)*ksm(3,n-i)%mod)%mod; cnt++; } } o((ans+ksm(2,cnt))%mod); }