codeforces 306C White, Black and White Again

来源:互联网 发布:android eventbus源码 编辑:程序博客网 时间:2024/05/21 19:48
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 nextn days. Polycarpus knows that he is in forw 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 ofn 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 modulo1000000009 (109 + 9).

Input

The single line of the input contains integers n,w and b (3 ≤ n ≤ 4000,2 ≤ w ≤ 4000, 1 ≤ b ≤ 4000) — the number of days, the number of good events and the number of not-so-good events. It is guaranteed thatw + 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".





【分析】

切水题系列...

枚举坏事发生了多少天,根据隔板法方案数,O(1)计算即可。

注意要乘阶乘,因为一些事在同一天发生的顺序要考虑到。




【代码】

//codeforces 306C White, Black and White Again#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define ll long long#define fo(i,j,k) for(int i=j;i<=k;i++)using namespace std;const int mod=1e9+9; const int mxn=4005;int n,w,b;ll ans,res;ll c[mxn][mxn],fac[mxn];inline void init(){int tmp=max(n,max(w,b));fo(i,0,tmp) c[i][0]=1;fo(i,1,tmp)  fo(j,1,i)    c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;fac[0]=1;fo(i,1,max(w,b)) fac[i]=(i*fac[i-1])%mod;}int main(){scanf("%d%d%d",&n,&w,&b);init();fo(i,1,b){ll res=n-i-1;if(!res) break;res=res*c[b-1][i-1]%mod;res=res*fac[b]%mod;res=res*c[w-1][n-i-1]%mod;res=res*fac[w]%mod;ans=(ans+res)%mod;}printf("%I64d\n",ans);return 0;}//100 200 300


0 0
原创粉丝点击