codeforces 306C White, Black and White Again
来源:互联网 发布:android eventbus源码 编辑:程序博客网 时间:2024/05/21 19:48
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).
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.
Print the required number of ways modulo 1000000009(109 + 9).
3 2 1
2
4 2 2
4
3 2 2
4
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
- Codeforces 306C White, Black and White Again (简单计数)
- codeforces 306C White, Black and White Again
- Codeforces 306C White, Black and White Again
- White, Black and White Again )(CodeForces
- CF306C:White, Black and White Again(组合数)
- Codeforces 260D - Black and White Tree
- Black And White
- Black And White
- Black and white hdu3633
- hdu3911 Black And White
- hdu3911---Black And White
- HDU5113 Black And White
- Black And White HDU
- Black And White
- CodeForces 260D Black And White Tree 贪心
- hdu 3911 Black and White
- hdu 3911 Black And White
- hdu 3911 Black And White
- 《逆向工程核心原理》<04-30> 通过Debug修改代码实现API钩取的技术
- Linux运维笔记-文档总结-ldap网络帐号
- 从输入URL到页面加载完成的过程详解
- C++类、对象等的基本概念
- 今天遇到这样一个面试题,在此记录一下
- codeforces 306C White, Black and White Again
- CCF NOI1142 质数
- 小菜鸟学习SpringMVC(一)
- 库(lib)与jar包有什么区别啊?
- 数据库系统概论学习攻略3
- 九度1013:开门人和关门人(优先队列)
- 文件上传和下载-ServletFileUpload
- 《Cracking the Coding Interview程序员面试金典》----数字发音
- JAVA中2.0-1.1不是0.9的问题