GYM 100883 G.Count Mix Strings(组合数学)
来源:互联网 发布:beta理财师软件 编辑:程序博客网 时间:2024/06/10 09:49
Description
给出两个长度分别为n和m的字符串a和b,要求在不改变两个串内部的先后顺序的条件下把两个串并在一起,问情况数(算重)
Input
第一行一整数T表示用例组数,每组用例输入两个整数n和m表示两个串的长度(1<=T,n,m<=10000)
Output
输出方案数
Sample Input
3
1 1
1 2
2 2
Sample Output
2
3
6
Solution
显然答案为C(n+m,n)
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 22222const ll mod=1000000007ll;ll f[maxn],inv[maxn];ll mod_pow(ll a,ll b,ll mod){ ll ans=1ll; while(b) { if(b&1)ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans;}void init(){ f[0]=inv[0]=1; for(int i=1;i<=20000;i++)f[i]=1ll*i*f[i-1]%mod,inv[i]=mod_pow(f[i],mod-2,mod);}ll deal(int n,int m){ return f[n+m]*inv[n]%mod*inv[m]%mod;}int main(){ init(); int T,n,m; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); ll ans=deal(n,m); printf("%I64d\n",ans); } return 0;}
0 0
- GYM 100883 G.Count Mix Strings(组合数学)
- Gym 100883G Count Mix Strings (Lucas,乘法逆元,扩展gcd,快速幂)
- GYM 100883 F.Print Mix Strings(枚举)
- Codeforces Gym 100589F Count Ways(DP+组合数学)
- Codeforces gym 101350G 数学
- GYM 100030 A. Innovative Experiment(组合数学)
- GYM 100030 C.Pink Elephants(组合数学)
- HDU 4372 Count the Buildings(组合数学-斯特林数,组合数学-排列组合)
- 组合数学(斯特林数) hdu 4372 ( Count the Buildings )
- CodeForces 630 G. Challenge Pennants(组合数学)
- CodeForces - 630G Challenge Pennants (组合数学)
- codeforces 630G Challenge Pennants(组合数学)
- CodeForces 630 G. Challenge Pennants(组合数学)
- GYM 100285 E. The Emperor’s plan(组合数学+dp)
- HDU4372 Count the Buildings ---组合数学
- HDU 4372 Count the Buildings 组合数学
- Gym 100712D Alternating Strings (dp)
- GYM 100247 B. Similar Strings(水~)
- MYSQL数据库基本DDL语句
- CodeForces 779D String Game【二分答案】
- 使用MockMvc测试Spring mvc Controller
- Java 抽象类
- java的十道基础面试题
- GYM 100883 G.Count Mix Strings(组合数学)
- 打不开tpl文件?eclipse对.tpl文件的支持
- CentOS 6.5 安装Apache服务器后无法访问解决方法
- Android基础知识一(Intent)
- Floodlight 入门 之 起步篇
- Android 7.0 Doze模式分析
- Spring中@Autowired注解、@Resource注解的区别
- Java 封装
- InnoDB存储引擎——两次写