瞬间移动
Accepts: 1018
Submissions: 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; }
时间: 2024-10-22 03:54:32