E - Roaming Atcoder

Problem solution: https://blog.csdn.net/qq_40655981/article/details/104459253

Subject to the effect: n rooms ,, each room has a people, a total of k days, one day, a person can go to any room. N ask how many rooms there are a state.

Everyone up to choose n-1 bedroom, if k> = n-1, the result is C (n + m-1, n-1) is similar to the ball-box model, that is, C (n + n-1, n-1).

If k <n-1, then certainly there will be n-1-k individual can not be moved. We subtracted the total of the line is not satisfied, the individual does not move with x, x ~ (1, n-1-k) condition is not satisfied.

C is calculated does not meet the conditions of the (n, x) * C (n-1, x-1) (do not understand, then the probability of wheels did not learn, like me).

 

CODE

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll ksm(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1) res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res%mod;
}
ll cal(ll n,ll m){
    ll sum1=1;
    ll sum2=1;
    for(ll i=1;i<=m;i++) sum1=sum1*i%mod;
    for(ll i=n;i>=n-m+1;i--) sum2=sum2*i%mod;
    return sum2*ksm(sum1,mod-2)%mod;
}
int  main(){
    ll n,k;
    cin>>n>>k;
    if(n-k<=1) cout<<cal(2*n-1,n-1)%mod<<endl;
    else{
        ll toll=cal(2*n-1,n-1)%mod;
        ll tmp1cal = (n, 1 )% v; 
        ll TMP 2 = 1 ; 
        Toll = (Toll-TMP 1 TMP 2% * v + v)% v;
        for (II i = 2 ; i <nk; i ++ ) { 
            TMP1 = TMP1 * (n-i + 1 )% v; 
            TMP1 = TMP1 ksm * (i, counter 2 )% v; 
            TMP 2 = TMP 2 * (n-i + 1 )% v; 
            TMP 2 = TMP 2 ksm * (i- 1 , MOD 2 )% v; 
            Toll = (Toll-TMP 1 TMP 2% * v + v)% v; 
        }
        cout<<toll<<endl;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Accepting/p/12356882.html