本文主要是介绍1152: [CTSC2006]歌唱王国Singleland,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这两题很类似,看看上面题解即可
c++代码如下:
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x ;i <= y;++ i)
#define repd(i,x,y) for(register int i = x ; i >= y;-- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{x = 0;char c;int sign = 1;do { c = getchar(); if(c == '-') sign =- 1; }while(!isdigit(c));do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));x *= sign;
}const int p = 1e4,N = 1e5 + 50;
int n,t,f[N],a[N],nxt[N],len;inline void get()
{int p = 0;rep(i,2,len){while(p && a[p + 1] != a[i]) p = nxt[p];if(a[p + 1] == a[i]) ++p;nxt[i] = p;}
}int main()
{read(n); read(t); n %= p;rep(i,1,t){read(len);rep(j,1,len) read(a[j]);get();int k = n;rep(i,1,len){f[i] = (f[nxt[i]] + k) % p;k = k * n % p;}printf("%04d\n",f[len]);}return 0;
}
这篇关于1152: [CTSC2006]歌唱王国Singleland的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!