Alien Flowers
2024-09-03 04:38:51
题意:
求含有A个"RR",B个"RB",C个"BB",D个"BR"的字符串个数。
解法:
首先考虑"BR"与"RB",我们可以首先"B","R"相间来排列进而满足B,D的限制。
这样,我们只需要考虑将"BB"和"RR"塞入初始得到的串即可,考虑隔板法。
PS:这题数据"0 0 0 0"有毒。
#include <iostream>
#include <cstdio>
#include <cstring> #define LL long long
#define P 1000000007LL
#define N 100010 using namespace std; int a,b,c,d;
LL fac[N*]; LL qpow(LL x,int n)
{
LL ans=;
for(;n;n>>=,x=x*x%P)
if(n&) ans=ans*x%P;
return ans;
} LL C(int n,int m)
{
if(m==) return 1LL;
return fac[n]*qpow(fac[n-m],P-)%P*qpow(fac[m],P-)%P;
} int main()
{
fac[]=;
for(int i=;i<*N;i++) fac[i] = fac[i-]*(LL)i%P;
while(~scanf("%d%d%d%d",&a,&b,&c,&d))
{
if(b== && d==)
{
if(a!= && c!=) puts("");
else if(a!= || c!=) puts("");
else puts("");
continue;
}
LL ans;
if(b==d)
{
ans = C(c+b-,b-)*C(a+b,b)%P;
ans += C(c+b,b)*C(a+b-,b-)%P;
if(ans>=P) ans-=P;
cout << ans << endl;
}
else if(b==d+ || d==b+)
{
b = max(b,d);
ans = C(b+c-,b-)*C(b+a-,b-)%P;
cout << ans << endl;
}
else puts("");
}
return ;
}
最新文章
- android 创建数组
- 比较器:Compare接口与Comparator接口区别与理解
- Android事件分发机制理解
- HttpHandler过滤请求..
- NBU官方Doc網址https://www.veritas.com/support/en_US/article.DOC5332
- C语言连接SQLSERVER数据库
- CodeForces#275--DIV 2--B(BinarySearch)(!!)
- 盘点mysql中容易被我们误会的地方
- linux进程用户内存空间和内核空间
- input file类型,文件类型的限制
- oracle安装后登录
- golang的推荐的orm库
- 重装linux后
- JavaScript之引用类型讲解
- 项目图片上传存储的目录部分代码思路Calendar类获取年月日
- 屏蔽全部统计代码(51.la cnzz 百度统计 谷歌分析师adsense、屏蔽淘宝客广告代码)的方法
- 简单说说Markdown语法
- POJ2762 Going from u to v or from v to u? 强连通分量缩点+拓扑排序
- 高阶函数 map、reduce、filter、sort 函数计算
- Ubuntu 16.04 编译OpenCV 问题解决stdlib.h: No such file or directory