Alien Flowers
题意:
求含有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的更多相关文章
- [LeetCode] Alien Dictionary 另类字典
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- ZOJ 3696 Alien's Organ
泊松分布.... Alien's Organ Time Limit: 2 Seconds Memory Limit: 65536 KB There's an alien whose name ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 269. Alien Dictionary 另类字典 *HARD*
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- Alien Dictionary
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
随机推荐
- UDP用户数据报协议和IP分组
UDP总体的封装格式例如以下: 以下是8字节UDP首部: 当IP层依据协议字段把UDP报文向上传送到UDP模块后,UDP模块再依据port号将数据发送到对应的进程中,以此实现进程到进程间的通信. 16 ...
- python(23)- 面向对象简单介绍
面向概述 面向过程:根据业务逻辑从上到下写垒代码 面向过程的设计的核心是过程,过程即解决问题的步骤, 面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西 优点:极大降低了程序的复杂 ...
- PHP中的$_SERVER['PATH_INFO']
PHP中的全局变量$_SERVER['PATH_INFO']是一个很有用的参数,众多的CMS系统在美化自己的URL的时候,都用到了这个参数. 对于下面这个网址: http://www.test.com ...
- 零基础学python-4.5 标准类型分类
1.按存储分:原子类型和容器类型 原子类型:仅仅能包括一个对象 容器类型:能够包括多个对象 分类 python类型 原子类型 数值和字符串 容器类型 列表.元组和字典 2.按能否够变化分:可变和不可变 ...
- iOS开发 - UIViewController控制器管理
创建一个控制器 控制器常见的创建方式有下面几种 //通过storyboard创建 //直接创建 ViewController *vc = [[ViewController alloc] init]; ...
- JavaScript事件在WebKit中的处理流程研究
本文主要探讨了JavaScript事件在WebKit中的注冊和触发机制. JS事件有两种注冊方式: 通过DOM节点的属性加入或者通过node.addEventListener()函数注冊: 通过DOM ...
- Dash 使用
花了 160 买了这个软件,至少看一遍它的 user guide,钱不能白花. https://kapeli.com/guide/guide.html 设置全局快捷键 Preference -> ...
- switch多分枝语句
package lianxi; //switch多分枝语句 import java.util.Scanner; public class GetSwitch { public static void ...
- EasyPusher手机直播编码推送之图像旋转90度后画面重复的问题
本文转自EasyDarwin开源团队开发Holo的博客:http://blog.csdn.net/holo_easydarwin 最初在做EasyPusher手机直播的时候遇到过一个问题:手机竖屏推送 ...
- ASP.NET MVC4中ViewBag、ViewData和TempData的使用和区别
一.说明 本文章主要是讲解asp.net mvc中ViewBag.ViewData和TempData的使用和区别,ViewBag.ViewData和TempData常常用于将action方法中的数据传 ...