转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Vasily the Bear and Beautiful Strings

Vasily the Bear loves beautiful strings. String s is beautiful if it meets the following criteria:

  1. String s only consists of characters 0 and 1, at that character 0 must occur in string s exactly n times, and character 1 must occur exactly m times.
  2. We can obtain character g from string s with some (possibly, zero) number of modifications. The character g equals either zero or one.

A modification of string with length at least two is the following operation: we replace two last characters from the string by exactly one other character. This character equals one if it replaces two zeros, otherwise it equals zero. For example, one modification transforms string "01010" into string "0100", two modifications transform it to "011". It is forbidden to modify a string with length less than two.

Help the Bear, count the number of beautiful strings. As the number of beautiful strings can be rather large, print the remainder after dividing the number by 1000000007 (109 + 7).

Input

The first line of the input contains three space-separated integers n, m, g (0 ≤ n, m ≤ 105, n + m ≥ 1, 0 ≤ g ≤ 1).

Output

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Sample test(s)
input
1 1 0
output
2
input
2 2 0
output
4
input
1 1 1
output
0
Note

In the first sample the beautiful strings are: "01", "10".

In the second sample the beautiful strings are: "0011", "1001", "1010", "1100".

In the third sample there are no beautiful strings.

注意边界时候的特殊情况即可

 //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define MAXN 200010
ll fac[];
const ll MOD = ;
void ext_gcd(ll a,ll b,ll &d,ll &x,ll &y){
if(!b){d=a,x=,y=;}
else{
ext_gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
ll inv(ll a){
ll d,x,y;
ext_gcd(a,MOD,d,x,y);
return d== ? (x+MOD)%MOD : -;
}
ll C(int a,int b){
ll ret=fac[a];
ret=ret*inv(fac[b])%MOD;
ret=ret*inv(fac[a-b])%MOD;
return ret;
}
int main()
{
ios::sync_with_stdio(false);
int n,m,g;
fac[]=;
for(int i=;i<MAXN;i++)fac[i]=fac[i-]*i%MOD;
cin>>n>>m>>g;
ll ans=;
if(!n){
if(m==)ans=;
else ans=;
if(g)ans=-ans;
cout<<ans<<endl;
}else if(m==){
if(n&)ans=;
else ans=;
if(g)ans=-ans;
cout<<ans<<endl;
}else{
ll tot=C(n+m,n);
ans=;
for(int i=;i<=n;i+=)
ans=(ans+C(n+m--i,m-))%MOD;
if(m==){
if(n&)ans++;
else ans--;
}
ans=(ans+MOD)%MOD;
if(g)ans=(tot-ans+MOD)%MOD;
cout<<ans<<endl;
}
return ;
}

codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)的更多相关文章

  1. codeforces 336D. Vasily the Bear and Beautiful Strings 组合数学 dp

    题意: 给出n,m,g,求好串的个数 0 <= n,m <= 10^5,n + m >= 1,0 <= g <= 1 好串的定义: 1.只由0,1组成,并且恰好有n个0, ...

  2. Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings

    这场CF,脑子乱死啊...C题,搞了很长时间,结束了,才想到怎么做.B题,没看,D题,今天看了一下,很不错的组合题. 如果n和m都挺多的时候 以下情况都是变为1,根据偶数个0,最后将会为1,奇数个0, ...

  3. codeforces 336C Vasily the Bear and Sequence(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Sequence Vasily the b ...

  4. codeforces C. Vasily the Bear and Sequence 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b ...

  5. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

  6. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  7. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  8. Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle

    水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using name ...

  9. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

随机推荐

  1. Linux Shell(初识)

    什么是Shell:Shell是一个命令解释器. Linux下支持shell的种类: 1.  Bourne Shell(简称sh) 2.C Shell(简称csh) 3.Korn Shell(简称ksh ...

  2. 读mongoose api 记录

    mongoose 需要在Schemas基础上进行使用 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var blo ...

  3. SVN上传代码时代码失败

    Description : You are not authorized to access the files in the repository.Suggestion : You might be ...

  4. 使用ownCloud搭建你的个人云服务(ubuntu 14.04 server)(ownCloud对文件不切片,Seafile对文件切片),owncloud没有存储的功能 只能同步 本地删除了服务器也会删除

    ownCloud是什么 ownCloud是一个自由且开源的个人云存储解决方案(类似百度网盘或者Dropbox),包括两个部分:服务器和客户端. ownCloud在客户端可通过网页界面,或者安装专用的客 ...

  5. python 文件中的中文编码解决方法

    # -*- coding: utf-8 -*- #查看安装的SDK默认的编码字符集在脚本中可以修改你的编码格式, 方法如下:#sys.getdefaultencoding()#reload(sys)# ...

  6. Qt String 与char* char int之间的转换

    下面CSDN的博客已经描述的很好了.不写了 references: http://blog.csdn.net/ei__nino/article/details/7297791 http://blog. ...

  7. linux环境c++开发:ubuntu12.04使用llvm3.4.2

    什么是 clang/llvm/libc++[1] clang 是最近几年(在大财主苹果的支持下)发展得非常好的 C 家族语言 (包括C/C++/Obj-C/Obj-C++) 编译器前端,所谓前端,就是 ...

  8. perl 对象 通过bless实现

    对象只是一种特殊的引用,它知道自己是和哪个类关联在一起的,而构造器知道如何创建那种关联关系. 这些构造器是通过使用bless操作符,将一个普通的引用物转换成一个对象实现的,

  9. UML--建模

    建模公式 这种精华的东西,一定是值得研读和实践的! myself:人,事,物,规则. 人,业务主角.业务工人.参与者.如果应用到教务系统中,就是管理员,主任,老师的关系. 事,业务用例,系统用例. 物 ...

  10. voijs1883 月光的魔法

    背景 影几欺哄了众生了天以外——月儿何曾圆缺 描述 有些东西就如同月光的魔法一般. Luke是爱着vijos的.他想为自己心爱的东西画些什么. 就画N个圆吧.把它们的圆心都固定在x轴上. 圆与圆.为了 ...