CF306C:White, Black and White Again(组合数)

来源:互联网 发布:js设置select不可用 编辑:程序博客网 时间:2024/06/10 18:19

C. White, Black and White Again
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to take place during each day. As each day is unequivocally characterizes as a part of a white or a black stripe, then each day is going to have events of the same type only (ether good or not-so-good).

What is the number of distinct ways this scenario can develop over the next n days if Polycarpus is in for a white stripe (a stripe that has good events only, the stripe's length is at least 1 day), the a black stripe (a stripe that has not-so-good events only, the stripe's length is at least 1 day) and a white stripe again (a stripe that has good events only, the stripe's length is at least 1 day). Each of n days will belong to one of the three stripes only.

Note that even the events of the same type are distinct from each other. Even if some events occur on the same day, they go in some order (there are no simultaneous events).

Write a code that prints the number of possible configurations to sort the events into days. See the samples for clarifications on which scenarios should be considered distinct. Print the answer modulo 1000000009 (109 + 9).

Input

The single line of the input contains integers nw and b (3 ≤ n ≤ 40002 ≤ w ≤ 40001 ≤ b ≤ 4000) — the number of days, the number of good events and the number of not-so-good events. It is guaranteed that w + b ≥ n.

Output

Print the required number of ways modulo 1000000009 (109 + 9).

Examples
input
3 2 1
output
2
input
4 2 2
output
4
input
3 2 2
output
4
Note

We'll represent the good events by numbers starting from 1 and the not-so-good events — by letters starting from 'a'. Vertical lines separate days.

In the first sample the possible ways are: "1|a|2" and "2|a|1". In the second sample the possible ways are: "1|a|b|2", "2|a|b|1", "1|b|a|2" and "2|b|a|1". In the third sample the possible ways are: "1|ab|2", "2|ab|1", "1|ba|2" and "2|ba|1".


题意:给出N,W,B,要求用W夹住B,然后将他们分成连续N份,每份里面不能同时出现W和B,且每个W和每个B都不一样,问方案数。

思路:组合数+隔板法,除了分割W和B的那两块板,还有N-3块板插进去。

# include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 8e3;const LL mod = 1e9+9;LL inv[maxn+3] = {1,1}, fac[maxn+3] = {1,1}, fi[maxn+3] = {1,1};void init(){    for(int i=2; i<=maxn; ++i)    {        fac[i] = fac[i-1]*i%mod;        inv[i] = (mod-mod/i)*inv[mod%i]%mod;        fi[i] = fi[i-1]*inv[i]%mod;    }}LL c(LL n, LL m){    return fac[n]*fi[n-m]%mod*fi[m]%mod;}int main(){    init();    LL n, w, b, ans = 0;    scanf("%I64d%I64d%I64d",&n,&w,&b);    for(LL i=1; i<w; ++i)    {        ans += c(w,i)*fac[i]%mod*fac[b]%mod*fac[w-i]%mod*c(w+b-3,n-3)%mod;        ans %= mod;    }    printf("%I64d\n",ans);    return 0;}



原创粉丝点击