【BZOJ】1152: [CTSC2006]歌唱王国Singleland

题解

读错题了,是最后留下一个牛人首长歌颂他,和其他人没有关系,t就相当于数据组数

结论题,具体可看
https://www.zhihu.com/question/59895916/answer/196874145

最后一个求导(1 - z)不拆,最后代入1的时候会消掉,就得出了这个结论

代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#define ivorysi
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mo 974711
#define RG register
#define MAXN 200005
using namespace std;
typedef long long int64;
typedef double db;
template
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template
void out(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
const int MOD = 10000;
int fpow(int x,int c) {
    int res = 1,t = x % MOD;
    while(c) {
    if(c & 1) res = res * t % MOD;
    t = t * t % MOD;
    c >>= 1;
    }
    return res;
}
int N,T,M,a[100005],fail[100005];
void Solve() {
    read(N);read(T);
    while(T--) {
    read(M);
    for(int i = 1 ; i <= M ; ++i) read(a[i]);
    fail[1] = 0;
    for(int i = 2 ; i <= M ; ++i) {
        int p = fail[i - 1];
        while(p && a[p + 1] != a[i]) p = fail[p];
        if(a[p + 1] == a[i]) fail[i] = p + 1;
        else fail[i] = 0;
    }
    int p = M,ans = 0;
    while(p) {
        ans += fpow(N,p);
        p = fail[p];
    }
    ans %= MOD;
    printf("%04d\n",ans);
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

转载于:https://www.cnblogs.com/ivorysi/p/9115107.html

你可能感兴趣的:(【BZOJ】1152: [CTSC2006]歌唱王国Singleland)