51nod 1120 机器人走方格V3 卡特兰数+卢卡斯定理
来源:互联网 发布:网络教育专业推荐 编辑:程序博客网 时间:2024/04/30 09:12
点这里
忘了好久的公式。。。终于想起来查
卡特兰数
卡特兰数计算公式C(2n-2,n-1)/n或C(2n,n)-C(2n,n-1)
卢卡斯定理 用于大组合数取模运算
ans=(C(2n-2,n-1)/n)%mod
#include <iostream>#include <string.h>#include <stdio.h>#include <math.h>using namespace std;typedef long long ll;const int maxn= 10010;const int mod=10007;int f[10020];void init(){ f[0]=1; for(int i=1;i<=maxn;i++) f[i]=(i*f[i-1])%mod;}long long pow1(long long n,long long m ){ long long ans = 1; while(m > 0) { if(m & 1)ans = (ans * n) % mod; m = m >> 1; n = (n * n) % mod;} return ans;}long long lucas(ll n,ll m){ ll ans=1; while(n&&m) { ll x,y; x=n%mod;y=m%mod; if(x<y) return 0; //printf("%lld %lld %d %d %d\n",x,y,f[x],f[y],f[x-y]); ans=ans*f[x]*pow1(f[y]*f[x-y]%mod,mod-2)%mod; n/=mod;m/=mod; } return ans%mod;}int main(){ init(); ll n,m,t; //freopen("out.txt","w",stdout);while(~scanf("%lld",&n)){ ll t=pow1(n,mod-2); printf("%lld\n",2*lucas(2*n-2,n-1)*t%mod);} return 0;}
阅读全文
0 0
- 51nod 1120 机器人走方格V3 卡特兰数+卢卡斯定理
- 51nod 1120 机器人走方格V3【卡特兰数】【卢卡斯定理】
- 51nod 1120 机器人走方格 V3(卡特兰数,lucas定理)
- 51nod 1120 机器人走方格V3(组合数学+卡特兰数+Lucas)
- 51nod 1120 机器人走方格 V3 lucas+卡特兰+逆原 好题
- 51NOD 1120 机器人走方格 V3(卢卡斯定理 + 非降路径)
- 51nod 1120 机器人走方格v3
- 51nod 1120 机器人走方格 V3
- 【51 Nod】 1120 机器人走方格 V3
- 51Nod-1120-机器人走方格 V3
- 51node-1120 机器人走方格(卡特兰数列+Lucas定理)
- 51Nod 1120 卡特兰数+卢卡斯定理
- [51nod-1120]机器人走方格V3 题解
- 2017-10-22 51nod 1120 卢卡斯定理 Lucas 组合数取模 卡特兰数
- 51nod 1119 机器人走方格 V2 费马小定理求组合数
- 51nod 1119 机器人走方格(费马小定理)
- 51nod 1119 机器人走方格(费马小定理)
- 51nod 1119 机器人走方格V2 lucas定理
- Java环境变量的配置流程
- Network-In-Network
- 机器学习十 交叉验证
- c++的this指针
- JSP中的四大作用域:page、request、session、application
- 51nod 1120 机器人走方格V3 卡特兰数+卢卡斯定理
- ShuffleNet
- netstat
- 【设计模式】单例设计模式
- opencv对图像的旋转操作以及尺寸改变
- 1028. List Sorting(25)
- java,python的spark环境搭建
- Xception
- .net面试题,各大企业常见的.net面试题之五