[Shoi2017] wish is to break up

Portal

Analysis showed that:

At most once for each switch, and it must be optimal from the back press (about because the number of impact, the impact can no longer be in front of the back of the large)

First you can handle at least need to press several times the "right" switch (from the back of the press are to ensure correct)

Half of the data satisfies k = n, or k is greater than the number of correctly pressed, this has nothing to do with a desired time, directly from the back press line.

Then take into account expectations related.

According to whether the desired number of steps to correct the relevant switch.

Set f [i] is the i-th switch is required to press the required number of steps desired by the switch i-1 times.

I-probability / n This step switch according to the right, (ni) / n, the probability of an error by the switch.

If you press the wrong switch, after the operation of the switch as necessary to back, so the more a ---> f [i + 1], press back, but also by the i-th to i-1 times - -> f [i], plus this time 1 itself.

Simplification what formula

#include<bits/stdc++.h>
#define LL long long
#define N 100003
#define mod 100003
using namespace std;
int read()
{
    int x=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
void print(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
int now[N];
LL f[N];
LL quick(LL a,LL x)
{
    LL ans=1;
    while(x)
    {
        if(x&1)ans=ans*a%mod;
        a=a*a%mod;x>>=1;
    }
    return ans;
}
int main()
{
    freopen("trennen.in","r",stdin);
    freopen("trennen.out","w",stdout);
    int n=read(),k=read();
    for(int i=1;i<=n;++i)now[i]=read();
    LL cnt=0;
    for(int i=n;i>=1;--i)
      if(now[i])
      {
          cnt++;
          for(int j=1;j*j<=i;++j)
            if(i%j==0)
            {
              now[j]^=1;
              if(j*j!=i)now[i/j]^=1;
          }
      }
    if(cnt<=k)
    {
        for(int I = 2 ; I <= n-; ++ I) 
          CNT = CNT * I% MOD; 
        the printf ( " % LLD \ n- " , CNT);    
         return  0 ; 
    } 
    F [n- + . 1 ] = 0 ;
     for ( int n = I; I> K; - I) // from the n pushed up by the n-th switches, from start to push it cnt, may press a start step number f not wrong and this state 
      f [i] = ( (n-+ (Ni) * F [I + . 1 ]% MOD))% MOD * Quick (I, mod- 2 )% MOD; 
    LL ANS = K;
     for ( int I = K + . 1 ; I <= CNT; ++i)
      ans=(ans+f[i])%mod;
    for(int i=2;i<=n;++i)
      ans=ans*i%mod;
    printf("%lld\n",ans);
} 
View Code

 

Guess you like

Origin www.cnblogs.com/yyys-/p/11574267.html