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下,可以使 ...
随机推荐
- 《Java多线程设计模式》学习
还是别人的笔记比较详细: https://segmentfault.com/blog/ressmix_multithread?page=3 mark.
- CF-1132 C.Painting the Fence
题目大意:现在有n个栅栏板,p个工人,每个工人可以涂一段区间的栅栏板,问如果雇佣p-2个工人,最多可以涂多少块栅栏板. 做法:先求出q个工人能涂得最多木板数,并统计每个木板被涂的次数.求被涂一次的木板 ...
- 【BZOJ3876】[AHOI2014&JSOI2014] 支线剧情(无源汇有上下界网络流)
点此看题面 大致题意: 有一张\(DAG\),经过每条边有一定时间,从\(1\)号点出发,随时可以返回\(1\)号点,求经过所有边的最短时间. 无源汇有上下界网络流 这是无源汇有上下界网络流的板子题. ...
- Jvisualvm简单使用教程
本博客介绍一下jvisualvm的简单使用教程,jvisualvm功能还是挺多的,不过本博客之简单介绍一下 1.拿线程快照信息 在jdk安装目录找到jvisualvm.exe,${JDK_HOME}\ ...
- Weblogic-SSRF漏洞复现
Weblogic-SSRF漏洞复现 一.SSRF概念 服务端请求伪造(Server-Side Request Forgery),是一种有攻击者构造形成有服务端发起请求的一个安全漏洞.一般情况下,SSR ...
- 如何取消 SqlDataAdapter.Fill() 的执行(转载)
问 Scenario: We have a DataGridView which is attached to DataAdapter (datatable), we load the data in ...
- asp.net面试题总结1(未完待续。。。。)
1.MVC中的TempData\ViewBag\ViewData区别? 答:页面对象传值,有这三种对象可以传. Temp:临时的 Bag:袋子 (1) TempData 保存在Session中,C ...
- python 处理中文遇到的编码问题总结 以及 字符str的编码如何判断
如何处理中午编码的问题 Python的UnicodeDecodeError: 'utf8' codec can't decode byte 0xxx in position 这个错误是因为你代码中的某 ...
- 妹纸对网易严选的Bra是什么评价?
声明:这是一篇超级严肃的技术文章,请本着学习交流的态度阅读,谢谢! 一.网易商品评论爬取 1.评论分析 进入到网易严选官网,搜索“文胸”后,先随便点进一个商品. 在商品页面,打开 Chrome 的控制 ...
- JDK1.8 Stream
Java 8 API添加了一个新的抽象称为流Stream,可以让你以一种声明的方式处理数据. Stream 使用一种类似用 SQL 语句从数据库查询数据的直观方式来提供一种对 Java 集合运算和表达 ...