题意:

求含有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. linux基础(5)- nginx服务、nfs服务

    一.nginx服务 源码安装: yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -yls ...

  2. Git bare repo with multiple branches

    http://stackoverflow.com/questions/9324762/git-bare-repo-with-multiple-branches Q: I want to make a ...

  3. GoogleFusionTablesAPI初探地图与云计算

    http://developer.51cto.com/art/200906/129324.htm http://yexiaochai.iteye.com/blog/1893735 http://yex ...

  4. gulp css html image js 合并压缩

    安装node.js  npm  以及安装gulp等方法我就不在这里赘述了. 接下里我主要介绍的是Gulpfile文件里面的配置该如何书写. var gulp = require('gulp');//引 ...

  5. 搭建React Native开发环境

    搭建React Native开发环境 本文档是Mac下搭建的环境,针对的目标平台不同,以及开发 iOS 和 Android 的不同,环境搭建也有差异. Github地址:https://github. ...

  6. LeetCode(70)题解: climbing-stairs

    https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps t ...

  7. ajax跨域请求的问题

    使用getJson跨域请求,需要向服务器发送一个参数callback=? $.getJSON("http://appcenter.mobitide.com/admin/appSearch.p ...

  8. go map 线程不安全 安全措施

    go map   线程不安全  安全措施

  9. mybatis入门(七)

    mybatis入门--添加一个用户 //添加用户 @Test public void insertUserTest() throws IOException { // 通过工厂得到SqlSession ...

  10. 【Effective C++】设计与声明

    条款18:让接口容易被正确使用,不易被误用 1,好的接口很容易被正确使用,不容易被误用.你应该在你的所有接口中努力达成这些性质. 2,“促进正使用”的办法包括接口的一致性,以及与内置类型的行为兼容. ...