题目描述
Count the number of n x m matrices A satisfying the following condition modulo (109+7).
* Ai, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤ j ≤ m.
* Ai, j ≤ Ai + 1, j for all 1 ≤ i < n, 1 ≤ j ≤ m.
* Ai, j ≤ Ai, j + 1 for all 1 ≤ i ≤ n, 1 ≤ j < m.
输入描述:
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and m.
输出描述:
For each test case, print an integer which denotes the result.
示例1
输入
复制
1 2
2 2
1000 1000
输出
复制
6
20
540949876
备注:
* 1 ≤ n, m ≤ 103
* The number of test cases does not exceed 105.
题意
给你一个nxm的矩阵让你向其中填{0,1,2}三个数且满足Ai,j⩽Ai+1,j
,Ai,j⩽Ai,j+1有几种填法。
从起点a1(0,0) 终点b1(n, m)画一条非降路径,然后0,1是沿着网格走的过程。
从起点a2(-1,1) 终点b2(n-1, m+1)画一条非降路径,然后1,2是沿着网格走的过程。
Lindström–Gessel–Viennot引理我们就可以求出2条严格不相交的路径的方案数
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e3+5;
const ll mod = 1e9+7;
ll c[maxn][maxn];
void init()
{
c[0][0] = 1;
for(int i = 1; i < maxn; i++)
{
c[i][0] = 1;
for(int j = 1; j <= i; j++)
c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
}
}
int main()
{
init();
int n,m;
while(~scanf("%d%d",&n,&m))
{
ll ans;
ans = (c[n+m][n]*c[n+m][n]%mod-c[n+m][n+1]*c[n+m][m+1]%mod+mod)%mod;
printf("%lld\n",ans);
}
return 0;
}