2018牛客多校第九场

E

#include
using namespace std;
const long long mod=1000000007,inv=570000004;
long long i,i0,n,m,T,a[1005],pre[1005][1005],mpow[1005],ans;
long long qpow(long long a,long long b,long long mod){long long r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
int main()
{
    scanf("%lld %lld",&n,&m);
    a[0]=a[n+1]=0,ans=0;
    for(i=1;i<=n;i++)scanf("%lld",&a[i]),mpow[i]=qpow(i,m,mod);
    for(i=1;i<=n;i++)
    {
        pre[i][i]=a[i]*inv%mod;
        for(i0=i+1;i0<=n;i0++)pre[i][i0]=pre[i][i0-1]*a[i0]%mod*inv%mod;
    }
    for(i=0;i<=n;i++)
    {
        for(i0=i+2;i0<=n+1;i0++)
        {
            ans+=pre[i+1][i0-1]*mpow[i0-i-1]%mod*(100-a[i])%mod*inv%mod*(100-a[i0])%mod*inv%mod;
            ans%=mod;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

F

#include 
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=500010;
 
char s[5][MAXN];
struct Mem{
    int id,pos;
    Mem(int _i=0,int _p=0){
        id=_i,pos=_p;
    }
};
stack ms;
int ans[MAXN];
struct Trie{
    int nexts[MAXN][26],fail[MAXN],ends[MAXN];
    queue que;
    vector G[MAXN];
    int dis[MAXN];
    int root,L;
    int newnode(){
        for(int i = 0;i < 26;i++)
            nexts[L][i] = -1;
        ends[L++]=0;
        return L-1;
    }
    void init(){
        L = 0;
        root = newnode();
    }
    void inserts(char buf[]){
        int len = strlen(buf);
        int now = root;
        for(int i = 0;i < len;i++){
            if(nexts[now][buf[i]-'a'] == -1)
                nexts[now][buf[i]-'a'] = newnode();
            now = nexts[now][buf[i]-'a'];
        }
        ends[now]++;
    }
    void build(){
        queueQ;
        fail[root] = root;
        for(int i = 0;i < 26;i++)
            if(nexts[root][i] == -1)
                nexts[root][i] = root;
            else{
                fail[nexts[root][i]] = root;
                Q.push(nexts[root][i]);
            }
        while( !Q.empty() ){
            int now = Q.front();
            Q.pop();
            ends[now]|=ends[fail[now]];
            for(int i = 0;i < 26;i++)
                if(nexts[now][i] == -1)
                    nexts[now][i] = nexts[fail[now]][i];
                else{
                    fail[nexts[now][i]]=nexts[fail[now]][i];
                    Q.push(nexts[now][i]);
                }
        }
 
        for(int u=0;u

 

你可能感兴趣的:(2018牛客多校第九场)