Urban (city): the number of combinations, inclusion and exclusion

A lot of people want to die yet. AC examination room on the marching.

No one wants this problem to write a good solution to a problem, because it is really quite simple estimate. . .

But to me it is not that simple ah! ! !

At least the topic and write their feet when the solution to a problem must think this question is sent to the sub-themes

Inclusion and exclusion, i enumeration has at least one condition is not satisfied, the program number is C (n, i) * C (mi * k-1, n-1).

Facing solution to a problem made a half-hour stay. I really is not ah what can I do.

Why not weight not leak ah? Why would a minimum, ah? Why would the inclusion-exclusion, ah? Why I have copied this formula only 30 sub-ah?

I guess not many people will see it a bit more so crap.

In fact, inclusion and exclusion is not difficult to think of, I think of the examination room.

But my idea of ​​a wave of Qing Qi, I think the "i happen to have a few cities does not meet the conditions of the program" inclusion-exclusion calculated

Total required out n, each complexity is n, the total complexity of n 2 .

Then roll to play violent.

But why should each seek out ah! Among them there will be no recurrence with no dependence ah.

So the brain is not.

So the question is only that I have to solve the problem when i = 0, solving just once.

Think of the examination room even, honesty is saved when the exp.

So consider how to solve it.

Problems "just" people feel a bit shy, then do not exactly, at least 0 okay?

It is extremely water, with no upper bound is quite limited, and the problem is n m was partitioned persons, at least 1.

Baffle law bare title. Is $ C ^ {n-1} _ {m-1} $ friends. This is quite simple.

At least 0 treatment is over, then at least one of it?

First elected one, $ C ^ 1_n $ in all cities.

Then the remaining vacant building team, choose the k chosen to give you that city, and the remaining sub-mk to all the n cities.

Or baffles method: $ C ^ {n-1} _ {mk-1} $

Note that you have chosen the city must continue to participate in the distribution, and then was assigned to at least one, otherwise it is just one and not more than k a k a.

At least two of it? Operators processes and meanings are the same: $ C ^ 2_n × C ^ {n-1} _ {mk * 2-1} $

至少i个呢?$ C^i_n × C^{n-1}_{m-k*i-1} $

At this point we finally got the solution to a problem inside the equation. (I would have lost at halfway)

Then you can the inclusion and exclusion. The rest is a bare inclusion and exclusion of the subject.

However, I could not even Qijia inclusion-exclusion will not even cut up. . .

For at least one case, which will comprise at least 2 of the case. . .

what. . . Then it is a binomial theorem permits inclusion and exclusion a thing (in fact, I will not)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 998244353
 4 #define int long long
 5 int inv[10000005],fac[10000005],invv[10000005],n,m,k;
 6 signed main(){
 7     scanf("%lld%lld%lld",&n,&m,&k);
 8     if(n>m){puts("0");return 0;}
 9     if(n==m){puts("1");return 0;}
10 //    if(m>n*k){puts("0");return 0;}
11     inv[0]=inv[1]=fac[1]=fac[0]=invv[1]=1;
12     for(int i=2;i<=m;++i)invv[i]=-mod/i*invv[mod%i]%mod,inv[i]=inv[i-1]*invv[i]%mod,fac[i]=fac[i-1]*i%mod;
13     int ans=fac[m-1]*inv[n-1]%mod*inv[m-n]%mod;
14     for(int i=1;i<=n&&i*k+n<=m;++i)ans=(ans+((i&1)?-1:1)*fac[n]*inv[i]%mod*inv[n-i]%mod*fac[m-i*k-1]%mod*inv[n-1]%mod*inv[m-i*k-n]%mod)%mod;
15     printf("%lld\n",(ans%mod+mod)%mod);
16 }
Paste the code ran

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/11327538.html