Breaking up is hospitalized 'expectations dp "

The big problem if you do, then God definitely "was second cut"

It is as if I have this even if the bar

answer

Consider first the situation is not random

Look descending enumeration is optimal,

Emotional understanding, you must choose a big, if you chose your small after big may make small flip current, your currently selected may be meaningless,

(That were so what you choose may have little impact on large, you choose a big impact on small will not)

Set f [i] denotes the i-th switch when you left the number of steps for a desired time

K then the last step the title selected from said optimal strategy useless, f [i] will be needed to select the optimal i.e. necessarily must be selected by a lamp f [i] = 1

So consider random,

Contribution of two parts, one. You need to press the press $ \ frac {i} {n} $ 2. Press without pressing the $ \ frac {ni} {n} * (f [i + 1] + f [i ] +1) $

After explain, should you choose to choose, you step to use $ 1 $ $ f [i + 1] $ state, and then you use the $ f [i + 1] $ ,, step back flip back to the current state you have to spend $ f [i] $ step to achieve the current election to the correct LED status (this formula reminds us of the tree this problem, do not you like)

About seeking mandatory collection, maintenance, use $ vector $ divisor on the line

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 1010101
#define mod 100003
ll f[A],a[A],inv[A];
ll cnt=0,n,k;
vector <ll> vec[A];
int main(){
    scanf("%lld%lld",&n,&k);
    f[n]=1;inv[1]=1;
    for(ll i=2;i<=n;i++) 
        inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    for(ll i=1,v;i<=n;i++)
        scanf("%lld",&a[i]);
    for(ll i=1;i<=n;i++)
        for(ll j=i;j<=n;j+=i)
            vec[j].push_back(i);
    for(ll i=n;i>=1;i--){
        if(!a[i]) continue ;
        for(ll j=0;j<vec[i].size();j++)
            a[vec[i][j]]^=1;
        cnt++;
    }
    for(ll i=n-1;i>k;i--)
        f[i]=(n+(n-i)*f[i+1]%mod)*inv[i]%mod;
    for(ll i=k;i>=1;i--)
        f[i]=1;
    ll ans=0;
    for(ll i=1;i<=cnt;i++)
        (ans+=f[i])%=mod;
    for(ll i=1;i<=n;i++)
        ans=ans*i%mod;
    printf("%lld\n",ans);
}
View Code

 

Guess you like

Origin www.cnblogs.com/znsbc-13/p/11616196.html