题意:

求含有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 ;
}

Alien Flowers的更多相关文章

  1. [LeetCode] Alien Dictionary 另类字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  2. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  3. ZOJ 3696 Alien's Organ

    泊松分布.... Alien's Organ Time Limit: 2 Seconds      Memory Limit: 65536 KB There's an alien whose name ...

  4. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  5. 269. Alien Dictionary 另类字典 *HARD*

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  6. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  7. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  8. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  9. Alien Dictionary

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

随机推荐

  1. android页面间传递对象

    android传递对象有两种方式: 一种是Serializable和Parcelable 对于第一种方式: import java.io.Serializable; public class Shop ...

  2. 云舒网络译:Rancher1.0正式版公布

    编者注: Rancher Labs是一家容器技术基础设施提供商,总部位于美国硅谷,Rancher是一个高效易用的企业容器云平台. 云舒网络 http://www.cloudsoar.com/为Ranc ...

  3. git操作演示

    阶段一: git init git config --global user.email "you@example.com" git config --global user.na ...

  4. storm是怎样保证at least once语义的

    背景 本篇看看storm是通过什么机制来保证消息至少处理一次的语义的. storm中的一些原语 要说明上面的问题,得先了解storm中的一些原语,比方: tuple和message 在storm中,消 ...

  5. 【BZOJ1483】[HNOI2009]梦幻布丁 链表+启发式合并

    [BZOJ1483][HNOI2009]梦幻布丁 Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2 ...

  6. EasyPusher安卓Android手机直播推送之MediaCodec 硬编码H264格式

    本文转自Holo的博客:http://blog.csdn.net/u013758734/article/details/50834770 最近在研究EasyDarwin的Push库EasyPusher ...

  7. 牛客练习赛14 D 比较月亮大小 【水】

    链接:https://www.nowcoder.com/acm/contest/82/D 来源:牛客网 比较月亮大小 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其 ...

  8. 关于node.js的安装与删除

    安装node.js 先切换到root用户安装 openssl-devel su - yum install openssl-devel 下载源代码自己编译以下代码中的tar.gz包根据node.js官 ...

  9. SPOJ1811 LCS SAM

    后缀自动机简单题. 其主要思路是,先对第一个字符串建立后缀自动机,把第二个串放在上面匹配, 若当前状态s有字符x的转移,直接转移len=step+1. 若当前状态s没有向字符x的转移,退回pres检查 ...

  10. codeforces 的 Codeforces Round #273 (Div. 2) --C Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...