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下,可以使 ...
随机推荐
- stm32配置led
前言:我们学习一门新语言的时候都是先从hello world入门,stm32也有自己的入门方式,那就是流水灯的配置. 在配置之前我们需要先配置好编译环境,我们需要手动修改头文件中的一些内容. 1.首先 ...
- vue_day05
目录 vue前后端交互: vue 分离前后端交互: vue前端发送请求: vue请求插件--axios: main.js配置: 前端朝后端请求传参方式: django后端返回数据样式: vue配置El ...
- H5开发 连接蓝牙打印机 打印标签(斑马ZR628)
1.连接蓝牙打印机(先用手机自带蓝牙进行配对),然后绑定出已配对的蓝牙设备(用来选择/切换打印机之用),代码如下 已配对蓝牙设备,中显示的就是已连接的,点击一下即可 代码: <!DOCTYPE ...
- CSS使用知识点
1.空白符 2.字符间距 3.省略号样式 4.水平垂直居中用法 5.CSS角标实现 空格符 1. 相当于键盘按下的空格,区别是 是可以累加的空格,键盘敲下的空格不会累加 2. ...
- 使用puppeteer爬取网页数据实践小结
简单介绍Puppeteer Puppeteer是一个Node库,它通过DevTools协议提供高级API来控制Chrome或Chromium.Puppeteer默认以无头方式运行,但可以配置为有头方式 ...
- Kubernetes生产架构浅谈
注意 本文,只是笔者针对Kubernetes生产环境运行的一些关于架构设计介绍. 介绍 基于 Kubernetes 系统构建的统一开发运维管控平台.在 Kubernetes 基础上,围绕 微服务系统的 ...
- maven pom项目的dependencies转gradle格式
1.新建一个文件件 2.创建pom.xm,放到新建的文件夹中 3.在命令行切换到新建文件夹中,执行: gradle init --type pom
- Java Scanner 类——获取用户的输入
创建Scanner对象语法 Scanner scan = new Scanner(System.in); 使用next()获取输入的字符串 import java.util.Scanner; publ ...
- 原生PHP和MYSQL练习登陆验证和查询数据到表格
直接上代码吧 <?php header("Content-type: text/html; charset=utf-8"); //数据量链接 $conn=mysqli_con ...
- WPF ItemsSource Order by Getter
public ObservableCollection<CustomerModel> CustomerCollection { get { if(customerCollection!=n ...