codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Vasily the Bear loves beautiful strings. String s is beautiful if it meets the following criteria:
- 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.
- 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).
The first line of the input contains three space-separated integers n, m, g (0 ≤ n, m ≤ 105, n + m ≥ 1, 0 ≤ g ≤ 1).
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
1 1 0
2
2 2 0
4
1 1 1
0
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(组合数学)的更多相关文章
- 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, ...
- Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings
这场CF,脑子乱死啊...C题,搞了很长时间,结束了,才想到怎么做.B题,没看,D题,今天看了一下,很不错的组合题. 如果n和m都挺多的时候 以下情况都是变为1,根据偶数个0,最后将会为1,奇数个0, ...
- codeforces 336C Vasily the Bear and Sequence(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Vasily the Bear and Sequence Vasily the b ...
- codeforces C. Vasily the Bear and Sequence 解题报告
题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- 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 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using name ...
- Educational Codeforces Round 8 C. Bear and String Distance 贪心
C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...
随机推荐
- 使用python发邮件
使用python发邮件 网上有很多发邮件的例子,本人在网上找了一份,稍加修改后使用 上源码 # encoding=utf-8 from email.mime.image import MIMEImag ...
- python视频教程大全集下载
python3英文视频教程(全87集) http://pan.baidu.com/s/1dDnGBvV Python从入门到精通视频(全60集)链接:http://pan.baidu.com/s/1e ...
- hibernate+spring+mvc+Easyui框架模式下使用grid++report的总结
最近刚开始接触hibernate+spring+mvc+Easyui框架,也是刚开通了博客,希望能记录一下自己实践出来的东西,让其他人少走弯路. 转让正题,以个人浅薄的认识hibernate对于开发人 ...
- mysql在关闭时的几个阶段
mysql关闭的大致过程 1.The shutdown process is initiated 初始化关机过程有许多种方法1.mysqladmin shutdown ; 2.kill pid_of_ ...
- 启动安卓模拟器报错 emulator: ERROR: x86_64 emulation currently requires hardware acceleration! CPU acceleration status:HAXM must be updated(version 1.1.1<6.0.1) 解决办法
启动安卓模拟器报错 emulator: ERROR: x86_64 emulation currently requires hardware acceleration! CPU accelerat ...
- [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product
Problem A. Minimum Scalar Product This contest is open for practice. You can try every problem as ...
- 通过IIS发布站点和VS2012自带发布网站
vs2012通过IIS发布站点 http://jingyan.baidu.com/article/0964eca2d7beeb8285f536bd.html 用VS2012自带发布网站 http:// ...
- 关appid
https://code.google.com/p/goagent/wiki/InstallGuide 申请appid
- poj3294 --Life Forms
Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12483 Accepted: 3501 Descr ...
- Linux备份与恢复
确定要备份的内容 在备份和还原系统时,Linux 基于文件的性质成了一个极大的优点.在 Windows 系统中,注册表与系统是非常相关的.配置和软件安装不仅仅是将文件放到系统上.因此,还原系统就需要有 ...