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 ...
随机推荐
- VS快速生成JSON数据类
1.复制Json数据 2.
- PHP中curl获取本机虚拟主机接口
在PHP的curl代码中增加header可解决此问题. $header = array( "Host: 你的域名(不能包含http://)", "Accept: text ...
- 一起talk GDB吧(第二回:GDB单步调试)
各位看官们,大家好.我们在上一回中说简单地介绍了GDB.这一回中,我们介绍GDB的调试功能:单步 调试. 闲话休提,言归正转. 让我们一起talk GDB吧! 看官们,我们先说一下什么是单步调试.大家 ...
- kubernetes的Service Account和secret
系列目录 Service Account Service Account概念的引入是基于这样的使用场景:运行在pod里的进程需要调用Kubernetes API以及非Kubernetes API的其它 ...
- 用python编写的无线AP扫描器
代码如下: #coding=utf-8 import os import sys import subprocess from scapy.all import * RSN = 48 #管理帧信息元素 ...
- A20 烧录和启动 log
用 LiveSuit 烧写了一个 lubuntu 的映像文件到板子上, 同时接了串口观察烧录过程的串口打印信息, 如下 ES: FES:Fes Ver: 098 FES:=============== ...
- PythonCookBook笔记——迭代器与生成器
迭代器与生成器 迭代是Python最强大的功能之一,虽然看起来迭代只是处理序列中元素的一种方法,但不仅仅如此. 手动遍历迭代器 想遍历但不想使用for循环. 使用next()方法并在代码中捕获Stop ...
- Mvc之Ajax上传图片
MyAjaxForm下载地址,点击此处下载 视图部分: @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Lay ...
- Android活动条(actionbar)使用具体解释(一)
活动条(ActionBar)是Android3.0的重要更新之中的一个.ActionBar位于传统标题的位置,其主要提供了例如以下功能: >显示选项菜单的菜单项,即激昂菜单项显示 ...
- struts2的核心和工作原理 (转)
转自--------http://blog.csdn.net/laner0515/article/details/27692673 在学习struts2之前,首先我们要明白使用struts2的目的是什 ...