转载请注明出处: 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. No2_4.接口继承多态_Java学习笔记_经典案例

    import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import jav ...

  2. 基于ViewPager的一些酷炫切换效果

    1.ViewPager可以用于实现类似banner的功能,我曾经在“时间超市”项目中使用过.但如何在此基础上实现一些切换的酷炫效果呢?今天细细品读了鸿洋大神的相关博文,终于学会了如何自定义切换效果. ...

  3. C语言float型数据在内存中的储存方式

  4. 正式学习react(二)

    今天把上一篇还没学习完的 webpack部分学习完: 之前有说过关于css的webpack使用.我们讲了 ExtractTextPlugin 来单独管理css讲了module.loaders下关于 c ...

  5. Unity3D 定时发射子弹

    using UnityEngine; public class example : MonoBehaviour { public GameObject projectilePrefab; public ...

  6. hdu 3832 Earth Hour

    http://acm.hdu.edu.cn/showproblem.php?pid=3832 #include <cstdio> #include <iostream> #in ...

  7. JQuery 图片延迟加载并等比缩放插件

    原文地址:http://www.shangxueba.com/jingyan/1909987.html DEMO地址:http://demo.jb51.net/html/jquery_img/jque ...

  8. uva1220--树的最大独立集+判重

    题意是挑选尽量多的人,并且每个人都不和他的父节点同时出现,很明显的最大独立集问题,难点在于如何判断方案是否唯一. 详情请见刘汝佳<算法竞赛入门经典--第二版>P282 #include&l ...

  9. soj 1700 ping_简单dp

    题目链接 题意:给你一个无向图,求n边的最短路 思路:用最短路想了半天都没想出来,比赛结束回去看看原来用dp做,我的dp有待提高啊 sp[i][k]=min(sp[j][k-1]+dp[j][i])/ ...

  10. 【shell】构造并遍历二位数组的一种用法

    参考shell数组的部分操作用法,实现了构造和遍历二维数组的一种方式,具体如下: #数组元素以空格分割 sites=("www.a.com www.b.com www.c.com www.d ...