题意:

求含有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. Cocos2d-x 3.0final 终结者系列教程15-win7+vs2012+adt+ndk环境搭建(无Cygwin)

    最终不用Cygwin 了.非常高兴 为什么要用Win7? 由于VS2012要求Win7以上系统才干安装! 为什么要用vs2012? 由于VS2012才支持C++11! 为什么要支持C++11? 由于C ...

  2. Phalcon框架如何实现读写分离

    Phalcon框架如何实现读写分离 假设你已经在DI容器里注册了俩 db services,如下: <?php // 主库 $di->setShared('dbWrite', functi ...

  3. *Android 多线程下载 仿下载助手(改进版)

    首先声明一点: 这里的多线程下载 并非指的 多个线程下载一个 文件.而是 每一个线程 负责一个文件. 真正的多线程 希望后面能给大家带来.  -------------  欢迎 爱学习的小伙伴 加群 ...

  4. JS 常用字符串操作

    Js字符串操作函数大全 /*******************************************                        字符串函数扩充              ...

  5. linux的su和sudo(转载)

    来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...

  6. 程序基石系列之C++多态的前提条件

    准备知识 C++中多态(polymorphism)有下面三个前提条件: 必须存在一个继承体系结构. 继承体系结构中的一些类必须具有同名的virtual成员函数(virtualkeyword) 至少有一 ...

  7. RYU改动监听port Mininet在custom自建拓扑和连接到指定控制器命令解释

    1.RYU控制器改动监听port 在ryu/ryu/ofproto以下的ofproto_common.py watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc ...

  8. 面试题三:设计包括 min 函数的栈。

    3.设计包括 min 函数的栈. 定义栈的数据结构,要求加入一个 min 函数.可以得到栈的最小元素. 要求函数 min.push 以及 pop 的时间复杂度都是 O(1). 思路分析: a.要想一个 ...

  9. UIAlertController Changes in iOS 8

    本文转载至 http://www.th7.cn/Program/IOS/201409/276000.shtml   As part of the theme of iOS 8 to make inte ...

  10. bootstrap-table 行内编辑

    1.文件引入 <link rel="stylesheet" href="bootstrap.css"> <link rel="sty ...