CF306C White, Black and White Again
CF306C White, Black and White Again
题目描述
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 nn days. Polycarpus knows that he is in for ww good events and bb 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 nn 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 nn 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 10000000091000000009 (10^{9}+9)(109+9) .
输入格式
The single line of the input contains integers nn , ww and bb ( 3<=n<=40003<=n<=4000 , 2<=w<=40002<=w<=4000 , 1<=b<=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>=nw+b>=n .
输出格式
Print the required number of ways modulo 10000000091000000009 (10^{9}+9)(109+9) .
题意翻译
PolycarpusPolycarpu**s 的生活总是满足“一些好事,然后一些坏事,然后一些好事”这样的规律。
所以 PolycarpusPolycarpu**s 认为接下来的 nn 天也是满足这样的规律的。
PolycarpusPolycarpu**s 知道,接下来会发生 ww 件两两不同的好事和 bb 件两两不同坏事,每天至少发生一件事,每天要么全部发生好事要么全部发生坏事。
由于 PolycarpusPolycarpu**s 的规律,这 nn 天会先有若干天发生好事,再有若干天发生坏事,再有若干天发生好事(若干代指>0>0)。
要求统计事件发生的方案数(每天发生的事的顺序也不一样),答案取模 10^9+9109+9 输出。
输入输出样例
输入 #1复制
输出 #1复制
输入 #2复制
输出 #2复制
输入 #3复制
输出 #3复制
说明/提示
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".
题解:
2019.10.16模拟赛爆氮T1
题面翻译来发第一篇题解...
首先拿到这道题手推了几组数据。然后灵光一闪:有没有可能是这些事件的发生顺序和到底发生在哪天并没有关系?就是说:我只需要把\(w\)件好事和\(b\)件坏事排成一排,保证\(b\)件坏事全在中间,两头都有好事即可。
但是这样绝对是不行的,因为我们把这些事件拆分成很多天(当然是满足题意的拆分方法),就是很多种方案。
但是这样的一个思路却为我们打开了一个突破口:在这样一个前面是一堆好事、中间夹了一堆坏事、最后又是一堆好事的序列中,我们只需要“往里添几个分隔板”,表示天数的差异,再进行统计即可。
隆重介绍:排列组合常用切题法:隔板法。
高中数学的排列组合会讲到,但是本蒟蒻并没有学.....简单介绍一下,排成一行的\(n\)件事,我们需要在其中的\(n-1\)个“缝隙”中,填入\(m\)个隔板,这样就把整个序列划分成了\(m+1\)个部分。
那么,我们有多少种合法的添入隔板的方法,就有多少种可能的天数划分方法。至于每天的事件发生顺序有所不同,我们只需要把天数划分方法乘上\(w!\times b!\)即可。(全排列公式)
于是,我们得到了一个组合数的公式:将\(n\)件事中填入\(m\)个隔板(分成了\(m+1\)个部分),方式有:(种)
\]
于是这道题就变成了一道组合数取模的题。
不要忘了最后要乘两个阶乘。因为数据范围已经给出,所以我们只需要考虑预处理出阶乘数组即可。
当然,也要顺道处理出乘法逆元的数组(除法取模要用)。
思路比较容易得出,但是不太容易理顺及证明正确性。而且代码的实现(取模)细节比较多,%……*&
代码如下:
#include<cstdio>
#define ll long long
#define mod 1000000009
using namespace std;
const int maxn=4001;
int fac[maxn],inv[maxn];
int n,w,b,ans;
void init_fact()
{
fac[0]=1;
for(int i=1;i<=maxn;i++)
fac[i]=(ll)i*fac[i-1]%mod;
}
void init_inv()
{
inv[0]=1;inv[1]=1;
for(int i=2;i<=maxn;i++)
inv[i]=mod-(ll)(mod/i)*inv[mod%i]%mod;
for(int i=1;i<=maxn;i++)
inv[i]=(ll)inv[i-1]*inv[i]%mod;
}
int calc(int n,int m)
{
return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
init_fact();
init_inv();
scanf("%d%d%d",&n,&w,&b);
for(int i=1;i<=b;i++)
if(n-i>=2 && n-i<=w)
ans=((ll)ans+(ll)(n-i-1)*calc(b-1,i-1)%mod*calc(w-1,n-i-1)%mod)%mod;
ans=(ll)((ll)ans*fac[w]%mod*fac[b]%mod)%mod;
printf("%d",ans);
return 0;
}
CF306C White, Black and White Again的更多相关文章
- [CF306C]White, Black and White Again_排列组合
White, Black and White Again 题目链接:https://www.luogu.org/problem/CF306C 数据范围:略. 题解: 记得不要看错题,容易看成来回交替下 ...
- SCU3185 Black and white(二分图最大点权独立集)
题目大概说有几个黑色.白色矩阵,问能选出黑白不相交的矩形面积和的最大值. 建二分图,黑色矩阵为X部的点,白色为Y部,XY的点权都为其矩阵面积,如果有个黑白矩阵相交则它们之间有一条边,那样问题就是要从这 ...
- white的配置使用
初次使用White来自动化测试10个9相加1.新建Visual C#->测试->单元测试项目2.在资源视图->引用,右键,添加引用,添加White的两个.dll文件3.在工程中添加命 ...
- CodeForces 1200D White Lines
cf题面 Time limit 1500 ms Memory limit 262144 kB 解题思路 官方题解 1200D - White Lines Let's consider a single ...
- 项目搭建(二):NUnit&TestStack.White
一.单元测试框架NUnit NUnit是所有.net语言的单元测试框架.使用C#语言编写. 测试框架:NUnit3 1. 安装NuGet包管理器 2. 在NuGet中安装NUnit.NUnit.Con ...
- EasyPR--开发详解(7)字符分割
大家好,好久不见了. 一转眼距离上一篇博客已经是4个月前的事了.要问博主这段时间去干了什么,我只能说:我去“外面看了看”. 图1 我想去看看 在外面跟几家创业公司谈了谈,交流了一些大数据与机器视觉相关 ...
- xamarin开发UWP元素的初始化设置顺序
在开发xamarin的UWP平台不可避免的遇到一下坑,现记录下来,希望对后面踩坑有帮助. 一.listview的分组问题:当我们使用listview的IsGroupingEnabled=true时,如 ...
- CSS3新特性应用之字体排印
一.插入换行 ~:表示同辈元素之后指定类型的元素,如;elm1 ~ elm2表示,elm1之后的所有elm2元素,且elm1与elm2都是在同一个父级元素. +:表示同辈元素的兄弟元素. \A:一个空 ...
- javascript中一些常见的兼容性问题
下面是一些Javascript的IE和Firefox(火狐)兼容性的常用例子 1. document.formName.item("itemName") 问题 说明:IE下,可以使 ...
随机推荐
- linux下如何查看自己都装了什么服务
service --status-all 先把rabbitmq进程杀掉 ps -ef | grep rabbitmq | grep -v grep | awk '{print $2}' | xargs ...
- client-go客户端自定义开发Kubernetes及源码分析
介绍 client-go 是一种能够与 Kubernetes 集群通信的客户端,通过它可以对 Kubernetes 集群中各资源类型进行 CRUD 操作,它有三大 client 类,分别为:Clien ...
- 九、Spring之BeanFactory源码分析(一)
Spring之BeanFactory源码分析(一) 注意:该随笔内容完全引自https://blog.csdn.net/u014634338/article/details/82865644,写的 ...
- Python3.0的新特性
网上关于Python3与Python2的区别的文章都烂大街了,但基本上都是抄来抄去,为了追本溯源,直接看官网最靠谱,官网文档的结构性更强. 本文是对Python3.0官网文档 What's New I ...
- 转 让FPGA替代GPU的6大顾虑,你确定不看看吗?
最近FPGA又频频被各AI领域的巨头看好,比如微软.百度.科大讯飞都对FPGA应用前景有所期待.那么如果让你选择FPGA作为AI计算系统的主力军,你会有什么样的顾虑? 这几天,已经退役的AlphaGo ...
- python随机选取目录下的若干个文件
个人记录用. python模块random argparse shutil import argparse parser = argparse.ArgumentParser() parser.add_ ...
- 读取txt文件内容,并按一定长度分页显示
private List<string> SaveContentUpload(FileUpload file) { List<string> list_content = ne ...
- 在Linux系统中运行并简单的测试RabbitMq容器
以前使用的是Windows下面的RabbitMq,需要先安装 Erlang的语言环境等,这次直接在Linux中的Docker容器来测试一下 1:docker配置RabbitMq的指令 docker r ...
- vertx-jersey
允许在vert.x中创建JAX-RS Jersey资源. 入门 将vertx-jersey依赖项添加到您的项目中 <dependency> <groupId>com.eng ...
- SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数据库的独占访问权
如果已经设置为单用户模式,还是报这个错误的话,就按照一下SQL执行就