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下,可以使 ...
随机推荐
- Bootstrap分页查询
前台方法: function show() { $('#reportTable').bootstrapTable({ method: 'get', url: "@Url.Action(&qu ...
- Docker入门之安装与使用
1. 安装(windows) win7.win8以及win10家庭版 等需要利用 docker toolbox 来安装,国内可以使用阿里云的镜像来下载,下载地址:http://mirrors.aliy ...
- 从应用到内核,分析top命令显示的进程名包含中括号"[]"的含义
背景 在执行top/ps命令的时候,在COMMAND一列,我们会发现,有些进程名被[]括起来了,例如 PID PPID USER STAT VSZ %VSZ %CPU COMMAND 1542 928 ...
- SpringBoot 整合RabbitMQ错误记录
1. 控制台报错:Exception in thread "main" java.io.IOException…… Caused by: com.rabbitmq.client.S ...
- idea中的后缀补全
IDEA有个很牛逼的功能,那就是后缀补全(Postfix Completion),这个功能可以通过后缀来使用代码补全进行模板式地补全语句,如遍历循环语句(for.foreach).使用 String. ...
- VS 插件 ReSharper 的个人习惯
个人习惯 1. 按 F12 恢复转到定义 很多时候,我个人不太喜欢一按 F12 就跳转到 ReSharper 自带的 查看代码浏览器,我还是喜欢 VS 默认的,于是点击菜单栏的 "RESHA ...
- 在进行机器学习建模时,为什么需要验证集(validation set)?
在进行机器学习建模时,为什么需要评估集(validation set)? 笔者最近有一篇文章被拒了,其中有一位审稿人提到论文中的一个问题:”应该在验证集上面调整参数,而不是在测试集“.笔者有些不明白为 ...
- Ubuntu关机重启后 NVIDIA-SMI 命令不能使用
问题: 电脑安装好Ubuntu系统后,后续安装了显卡驱动.CUDA.cuDNN等软件,后续一直没有关机.中间系统曾经有过升级,这也是问题所在.系统升级导致内核改变,并可能导致它与显卡驱动不再匹配,所以 ...
- QGIS中查看PostGIS空间数据库中的影像
在QGIS中的Browser中是无法显示PostGIS空间数据库中的影像 要找到影像显示打开"Database" –> "DB Manager" 右击-- ...
- 使用T4模板同时生成多个类文件
代码: <#@ template language="C#" debug="false" hostspecific="true"#&g ...