NC51067. ABBA
描述
输入描述
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and m.
*
* There are at most 2019 test cases, and at most 20 of them has .
输出描述
For each test case, print an integer which denotes the result.
示例1
输入:
1 2 1000 1000 0 0
输出:
13 436240410 1
C++14(g++5.4) 解法, 执行用时: 159ms, 内存消耗: 31844K, 提交时间: 2019-07-18 14:05:23
#include<cstdio> #include<cstring> #define M 1005 #define P 1000000007 int dp[M*4][M*2]; int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF){ int i,j; dp[0][M]=1; for(i=1;i<=2*(n+m);i++){ dp[i][M-m]=dp[i-1][M-m+1]; dp[i][M+n]=dp[i-1][M+n-1]; for(j=M-m+1;j<=M+n-1;j++) dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1])%P; } printf("%d\n",dp[2*(n+m)][M]); } return 0; }
C++(clang++11) 解法, 执行用时: 52ms, 内存消耗: 45800K, 提交时间: 2020-10-24 16:40:09
#include<bits/stdc++.h> using namespace std; int c[4005][4005],n,m,p=1e9+7; int main(){ for(int i=0;i<4005;i++) c[i][0]=c[i][i]=1; for(int i=1;i<4005;i++) for(int j=1;j<i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%p; while(cin>>n>>m) cout<<(0ll+c[n+m+n+m][n+m]-c[n+m+n+m][n-1]-c[n+m+n+m][m-1]+p+p+p)%p<<endl; return 0; }