1 条题解
-
0
#include<bits/stdc++.h> using namespace std; #define int long long #define lowbit(x) x&-x const int INF=0x3f3f3f3f3f3f3f3f; const int N=1e5+10; const int M=2e6+10; const int mod=1e9+7; string s; int n; int dp[N][2]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>s; n=s.size(); s=' '+s; dp[0][1]=1; for(int i=1;i<=n;i++){ if(s[i]=='0'){//这时候继承上面的 dp[i][0]+=dp[i-1][0]*3;//填01或10或00//万一前面的是0??这里保证一定更小满足(1,1)不等了 dp[i][1]+=dp[i-1][1];//(0,0)填(1,0)(0,1)炸了结果1大于了0 (00)没多 }else{ dp[i][0]+=dp[i-1][0]*3; dp[i][0]+=dp[i-1][1];//当前位置填00更小 dp[i][1]+=dp[i-1][1]*2;//当前位置填01或10(00)不行因为会变小 } dp[i][0]%=mod; dp[i][1]%=mod; } cout<<(dp[n][0]+dp[n][1])%mod; return 0; } /* 我们发现 异或相同为0不同为1 发现a^b<max(a,b)*2 也就是a和b<l 如果a^b=a+b a+b=a^b+2*a&b//相同的要加回去 所以a&b=0位置中没有有都有1的 从高位到低位 定义数位dp[i][0]处理完前i位后,所有满足a&b=0且已经确定小于L的方案数 dp[i][1]等于l */
信息
- ID
- 1720
- 时间
- 2000ms
- 内存
- 1024MiB
- 难度
- 提高
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者