https://vjudge.net/contest/198244#problem/D
给定一个二叉树,其深度为x,要求转弯y次,问你有多少路径?
(路径长度一定要为x)。
比赛的时候没有思路。。
后来发现,如果深度为x。那么只需要求C(x-1,y)次,再乘以2(0变成11变成0,即第二次转和不转的地方变换。)
:意识到了一些组合数学的基本模型都不太熟悉。
② 对于m,n比较小的话,可以用递推式来计算组合数
当m,n比较大,那么可以用定义的方法计算。(就是阶乘的那种定义)
对于m,n特别大(而mod比较小的话1e5左右),我们可以用lucas定理算。(这个不是特别会)
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int maxn = 1e5+7;
const int modd=1e9+7;
typedef long long ll;
ll fac[maxn];
ll qpow(ll a,ll b)
{
ll ans=1;a%=mod;
for(ll i=b;i;i>>=1,a=a*a%mod)
if(i&1)ans=ans*a%mod;
return ans;
}
ll C(ll n,ll m)
{
if(m>n||m<0)return 0;
ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-2)%mod;
}
ll p;
/*ll Lucas(ll n, ll m)
{
if(m == 0) return 1;
return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}*/
int main()
{
fac[0]=1;
for(int i=1;i<maxn;i++)
fac[i]=fac[i-1]*i%(modd);
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
scanf("%lld%lld",&a,&b);
ll ans=C(a-1,b);
ans=(ans*2)%mod;
printf("%lld\n",ans);
}
return 0;
}`这里写代码片`