做这题发现自己智商好他妈的低。。。。。。。这题一看我就觉得是dp,然后壮压,和开4维的dp都超时,理论上不应该超时啊 啊。没想到这题只有o(n)的复杂度才能过,我写了 一下午的dp。。。。
这题枚举第一列放雷的数量,后面怎么放(放1,放2,不放)就全固定了。然后就是暴力!!暴力!!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
const int maxn =10005;
const int inf =0x3f3f3f;
typedef long long LL;
using namespace std;
const int mod = 1e8 + 7;
char s[maxn];
int dp[maxn];
int main(){
int cases;
scanf("%d", &cases);
while (cases--){
scanf("%s", s + 1);
int n = strlen(s + 1);
int ans = 0;
for (int i = 0; i <= 2 && i <= s[1] - '0'; i++){
dp[1] = i;
bool judge = true;
for (int j = 2; j <= n; j++){
int num = s[j - 1] - '0' - dp[j - 1] - dp[j - 2];
if (num > 2 || num < 0){
judge = false;
break;
}
dp[j] = num;
}
if (judge&&dp[n - 1] + dp[n] == s[n] - '0'){
int now = 1;
for (int j = 1; j <= n; j++){
if (dp[j] == 1)
now *= 2;
else
now *= 1;
now %= mod;
}
ans += now;
ans %= mod;
}
}
printf("%d\n", ans);
}
}