installb
2020-05-11 20:32:39
题
我是先想的如果 1
不能变 0
应该怎么做,明显是个区间 DP。
代码写得很丑()
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 998244353;
map <string,LL> mp[2];
string u;
LL f(LL id,string s){
if(mp[id].find(s) != mp[id].end()) return mp[id][s];
LL ret = 0,len;
len = s.length();
if(id){
for(LL i = 0;i < len;i ++) ret = (ret + f(1,s.substr(0,i)) * f(0,s.substr(i,len))) % N;
mp[id][s] = ret; return ret;
}
else{
for(LL i = 1;i < len;i ++){
if(len % i) continue;
string t = "";
for(LL j = 0;j < i;j ++) t += '1';
for(LL j = 0;j < len;j += i){
for(LL k = 0;k < i;k ++){
if(s[j + k] == '0') t[k] = '0';
}
}
ret += f(1,t); ret %= N;
}
mp[id][s] = ret; return ret;
}
}
int main(){
mp[0][""] = mp[1][""] = 1;
mp[0]["0"] = 1; mp[0]["1"] = 2;
mp[1]["0"] = 1; mp[1]["1"] = 2;
cin >> u;
cout << f(1,u) << '\n';
return 0;
}