链接:戳这里
瞬间移动
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几种方案,答案对1000000007取模。

Input
多组测试数据。
两个整数n,m(2≤n,m≤100000)
Output
一个整数表示答案
Sample Input
4 5
Sample Output
10
思路:
直接递推一下n,m发现答案就是C(n+m-4,n-2) 由于要取模需要用到费马小
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
#define mod 1000000007
int n,m;
ll fac[1000010];
ll ppow(ll k,ll n) {
ll c=1;
while(n) {
if(n%2) c=(c*k)%mod;
k=(k*k)%mod;
n>>=1;
}
return c;
}
ll C(ll a,ll b) {
return (((fac[b]*ppow((fac[a]*fac[b-a])%mod,mod-2)))%mod)%mod;
}
int main(){
fac[0]=1;
for(int i=1;i<=1000000;i++) fac[i]=(fac[i-1]*i)%mod;
while(scanf("%d%d",&n,&m)!=EOF){
if(n==2 || m==2) {
cout<<1<<endl;
continue;
}
int x=n+m-4;
int y=n-2;
ll ans=C(y,x)%mod;
cout<<ans%mod<<endl;
}
return 0;
}