Codeforces 306C White, Black and White Again
来源:互联网 发布:淘宝进口牛肉便宜 编辑:程序博客网 时间:2024/05/22 01:45
首先枚举有几天是不好的天,然后用插板法计算时间的安排方式。答案是
#include<cstdio>#include<algorithm>using namespace std;#define LL long longconst int p=1000000009,maxn=4010;int cw[maxn],cb[maxn],inv[maxn],prm[maxn],tot,n,m,w,b;int pow(int x,int k){ int ret=1; for (;k;k>>=1,x=(LL)x*x%p) if (k&1) ret=(LL)ret*x%p; return ret;}int main(){ int ans=0; scanf("%d%d%d",&n,&w,&b); m=max(w,b); inv[1]=1; for (int i=2;i<=m;i++) { if (!inv[i]) { inv[i]=pow(i,p-2); prm[++tot]=i; } for (int j=1;i*prm[j]<=m;j++) { inv[i*prm[j]]=(LL)inv[i]*inv[prm[j]]%p; if (i%prm[j]==0) break; } } cw[0]=1; for (int i=1;i<w;i++) cw[i]=(LL)cw[i-1]*inv[i]%p*(w-i)%p; cb[0]=1; for (int i=1;i<b;i++) cb[i]=(LL)cb[i-1]*inv[i]%p*(b-i)%p; for (int i=max(1,n-w);i<=n-2&&i<=b;i++) ans=(ans+(LL)(n-i-1)*cw[n-i-1]%p*cb[i-1])%p; for (int i=2;i<=b;i++) ans=(LL)ans*i%p; for (int i=2;i<=w;i++) ans=(LL)ans*i%p; printf("%d\n",ans);}
0 0
- 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
- import of android.R
- weka之对id3实现可视化
- 如何删除itunes中的ipa安装包
- Go学习笔记(九)接口,错误处理
- PTA 乙级 1037. 在霍格沃茨找零钱(20)
- Codeforces 306C White, Black and White Again
- CMake生成VS2013项目失败的解决办法
- 推荐系统论文资料集
- 662
- linux 配置 jdk
- RabbitMQ-理解消息通信-消费者和生产者
- 进程通信概念和进程通信方式
- SVG:textPath深入理解
- make[1]: *** 警告:文件的修改时间在将来2.1e+07