链接:https://www.nowcoder.com/acm/contest/139/A
来源:牛客网
题目描述
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.
这题是套的Lindström–Gessel–Viennot lemma
具体的操作就是两个起点和两个中点,求不相交的路径条数。
其中要把1 2两个的边缘线向右下角平移(具体为什么这么操作一直搞不懂)
最后的种类就是一个两阶的行列式展开就是C(n+m,n)*C(n+m,n)-C(n+m,n-1)*C(n+m,n+1)。
附AC代码
#include <bits/stdc++.h>
#define me0(x) memset(x,0,sizeof(x))
#define ll long long
#define ull unsigned long long
#define scan(x) scanf("%d",&x)
#define scanll(x) scanf("%lld",&x)
#define dscan(x,y) scanf("%d%d",&x,&y)
#define rep(x,be,en) for (x=be;x<=en;x++)
#define fr1(n) for (int i=1;i<=n;i++)
#define fr(n) for (int i=0;i<n;i++)
const ll MOD=1e9+7;
using namespace std;
long long c[2000 + 5][2000 + 5];
void init()
{
for (int i = 0; i <= 1005; i++)
{
for (int j = 0; j <= 1005; j++)
{
if (i == 0 || j == 0)
c[i][j] = 1;
else
c[i][j] = (c[i - 1][j] + c[i][j - 1])%MOD;
}
}
}
int main()
{
int n, m;
init();
while (scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n", ((c[n][m] * c[n][m])%MOD - (c[m+1][n - 1] * c[n+1][m - 1]) % MOD+MOD) % MOD);
}
return 0;
}