zoukankan      html  css  js  c++  java
  • 【BZOJ】1152: [CTSC2006]歌唱王国Singleland

    题解

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

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

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

    代码

    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <map>
    //#define ivorysi
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #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<class T>
    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<class T>
    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
    ",ans);
        }
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    
  • 相关阅读:
    你所不知道的 CSS 阴影技巧与细节
    %date~0,4%和 %time~0,2%等用法详解
    计算程序执行时间
    GDI
    IO
    字符串拼凑批量Insert SQL语句神BUG
    用逗号分隔的数据转换到数组
    MVC ViewBag传值
    接口和抽象类对比
    Partial 同一个命名空间下写两个类名一样的类
  • 原文地址:https://www.cnblogs.com/ivorysi/p/9115107.html
Copyright © 2011-2022 走看看