标签:names n+2 sizeof space void mem name false str
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---
const int N = 155, P = 51123987;
int n, m;
int ne[N][3], f[N][55][55][55];
string s;
void add(int &a, int b) {
if((a+=b)>=P) a-=P;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n >> s;
s = " " + s;
memset(ne, -1, sizeof(ne));
for(int i = sz(s)-1; ~i; --i) {
rep(j, 0, 3) ne[i][j] = ne[i+1][j];
if(i) ne[i][s[i]-‘a‘] = i;
}
m = (n+2)/3;
f[0][0][0][0] = 1;
rep(i, 0, n+1) {
rep(a, 0, m+1) rep(b, 0, m+1) rep(c, 0, m+1) {
rep(j, 0, 3) if(~ne[i][j]) {
int t = ne[i][j];
add(f[t][a+(j==0)][b+(j==1)][c+(j==2)], f[i][a][b][c]);
}
}
}
int ans = 0, l = n/3, r = m;
rep(i, 1, n+1) {
rep(a, l, r+1) rep(b, l, r+1) rep(c, l, r+1) if(a+b+c==n) {
add(ans, f[i][a][b][c]);
}
}
cout << ans << endl;
return 0;
}
标签:names n+2 sizeof space void mem name false str
原文地址:https://www.cnblogs.com/wuyuanyuan/p/9255381.html