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 ...
随机推荐
- ci 的控制器文件夹下开加子文件夹
在一个比较大的项目中,希望controllers下再细分子文件夹.例如:controllers/pj,controllers/xxk等. 做法是: 1.在controllers下添加相关的子文件夹,例 ...
- mongoexport导出数据
mongoexport用法: /***** Export MongoDB data to CSV, TSV or JSON files.options: --help ...
- [POJ] 3368 / [UVA] 11235 - Frequent values [ST算法]
2007/2008 ACM International Collegiate Programming Contest University of Ulm Local Contest Problem F ...
- 那两年炼就的Android内功修养
http://blog.csdn.net/luoshengyang/article/details/8923485 http://iconsparadise.com/ http://blog.csdn ...
- 新版TeamTalk部署教程(蓝狐)
http://www.bluefoxah.org/teamtalk/new_tt_deploy.html
- 系统监控的工具tsar
近期一直在折腾着elasticsearch,需要对硬件进行评估 大概几方面 内存 cpu 硬盘 网络. iostat vmstat top 几个命令用了一堆,其实需要关注的几个点只要都列出来就可以了 ...
- 关于Microsoft app下同义词的整理
Windows os 以下词表达的是同一个概念 windows store app windows metro app windows modern app windows runtime app w ...
- print带参数格式
string_1 = "Camelot" string_2 = "place" print("float:%lf. int:%d string:%s. ...
- Mysql 创建用户并对其赋予操作权限
授权命令GRANT 语句的语法如下: GRANT privileges (columns) ON what TO user IDENTIFIEDBY "password" WITH ...
- UVa 147 Dollars(硬币转换)
题目大意:给出五种硬币,价值分别为 1,5,10,25,50,.当给出一个价值时,求出能够组合的种数(每种硬币可以用无限次). 思路:完全背包, dp[i][j]表示总数 i 能够被表示的种数.状态转 ...