hdu5698 Lucas 大组合数
来源:互联网 发布:南京大汉网络 双休 编辑:程序博客网 时间:2024/06/05 18:59
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5698
题目大意:有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第
思路:打个表,就可以找出规律了,求组合数。。。
n = n + m - 4;
m -= 2;
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <fstream>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <iomanip>using namespace std;//#pragma comment(linker, "/STACK:102400000,102400000")#define maxn 100050#define MOD 1000000007#define p 1000000007#define mem(a , b) memset(a , b , sizeof(a))#define LL long long#define ULL unsigned long long#define FOR(i , n) for(int i = 1 ; i<= n ; i ++)typedef pair<int , int> pii;const long long INF= 0x3fffffff;LL n,m;LL quick_mod(LL a, LL b){ LL ans = 1; a %= p; while(b) { if(b & 1) { ans = ans * a % p; b--; } b >>= 1; a = a * a % p; } return ans;}LL C(LL n, LL m){ if(m > n) return 0; LL ans = 1; for(int i=1; i<=m; i++) { LL a = (n + i - m) % p; LL b = i % p; ans = ans * (a * quick_mod(b, p-2) % p) % p; } return ans;}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(){ while(scanf("%I64d%I64d", &n, &m) != EOF) { if(n <= 1 || m <= 1) { printf("0\n"); continue; } //m -= 2; n = n + m - 4; m -= 2; printf("%I64d\n", Lucas(n,m)); } return 0;}
0 0
- hdu5698 Lucas 大组合数
- Lucas大组合数模板
- 组合数公式&Lucas大组合数
- 大组合数取模hdu5698 瞬间移动
- Lucas求组合数
- 组合数/Lucas定理
- 组合数 (Lucas)
- JOJ1595:Combinations(求解大组合数,Lucas定理)
- HDU 3037 Saving Beans 大组合数 lucas定理
- Lucas定理(大组合数的取模)
- [hdu5698]: 瞬间移动(两种方法求组合数)
- 组合数中的Lucas定理
- Lucas求解组合数模板
- hdu3037 组合数 lucas定理
- Lucas定理求组合数
- Lucas定理 大组合数取模
- Lucas定理与大组合数的取模的求法总结
- Lucas定理与大组合数的取模的求法总结
- spring mvc加载css,js等有关文件
- SpringMVC设计思路
- 在 SQL 数据库中保存数据
- 网易视频云分享:RC4加密算法
- MySQL中视图的定义、原理和如何使用、创建
- hdu5698 Lucas 大组合数
- [iOS] 限制输入中文的两个办法 ==>正则or键盘
- JSON基础
- c++单链表
- 同步与异步的概念
- ng-disabled 不起作用的解决办法
- Zend Studio使用教程之在Linux上进行安装
- IE版本
- iOS开发者如何写自己的用户行为统计(仿友盟统计)