2016"百度之星" - 初赛(Astar Round2B)1003 瞬间移动 组合数学+逆元
2016-05-22 16:40
369 查看
瞬间移动
Accepts: 1018Submissions: 3620
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第nn行第mm列的格子有几种方案,答案对10000000071000000007取模。
Input
多组测试数据。
两个整数n,m(2\leq n,m\leq 100000)n,m(2≤n,m≤100000)
Output
一个整数表示答案
Sample Input
4 5
Sample Output
10 思路:ans=C(n+m-4,n-2);
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll long long #define mod 1000000007 #define inf 999999999 #define pi 4*atan(1) //#pragma comment(linker, "/STACK:102400000,102400000") int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - '0' ; while( ( ch = getchar() ) >= '0' && ch <= '9' ) res = res * 10 + ( ch - '0' ) ; return res ; } void extend_Euclid(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return; } extend_Euclid(b, a % b, x, y); ll tmp = x; x = y; y = tmp - (a / b) * y; } ll combine1(ll n,ll m) //计算组合数C(n,m) { ll sum=1; //线性计算 for(ll i=1,j=n;i<=m;i++,j--) { sum*=j; sum%=mod; ll x,y; extend_Euclid(i,mod,x,y); sum*=(x%mod+mod)%mod; sum%=mod; } return sum; } int main() { ll x,y,z,i,t; while(~scanf("%I64d%I64d",&x,&y)) { ll n,k; ll ans=0; k=x-2; n=(x+y)-4; ans=combine1(n,k); printf("%I64d\n",ans); } return 0; }
相关文章推荐
- Python开发轻量级爬虫
- 切换淡出 / 滑动
- React Native 安装开发环境及如何编写Hello World程序
- Java中的文件和目录管理(下)----Path、Files
- JAVA之Math类常用数学运算记录
- 一步步学spark之一scala条件表达式1.4
- textField控制字数(字符16个)
- iOS面试和招聘
- 如何写出高效优美的单片机C语言代码?
- string.format()函数的用法
- 使用变量缓存jQuery对象
- android开发笔记之打造终极适配器
- Linux学习之多命令顺序执行
- JQuery利用sort对DOM元素进行排序
- Android 设置键盘弹出后顶起布局
- java学习记录
- Bring Your Android App to Chromebooks
- MySql 中文乱码
- 禁用输入字段
- Android BroadcastReceiver广播接收器详解