链接:https://www.nowcoder.com/acm/contest/139/A
来源:牛客网
题目描述
Count the number of n x m matrices A satisfying the following condition modulo (10
9+7).
* A i, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤ j ≤ m.
* A i, j ≤ A i + 1, j for all 1 ≤ i < n, 1 ≤ j ≤ m.
* A i, j ≤ A i, j + 1 for all 1 ≤ i ≤ n, 1 ≤ j < m.
* A i, j ∈ {0, 1, 2} for all 1 ≤ i ≤ n, 1 ≤ j ≤ m.
* A i, j ≤ A i + 1, j for all 1 ≤ i < n, 1 ≤ j ≤ m.
* A i, j ≤ A i, 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 ≤ n, m ≤ 103
5
* The number of test cases does not exceed 10
.
给你一个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条严格不相交的路径的方案数
LGV引理的具体描述:见wiki
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; typedef long long ll; ll f[2100][2100]; void init(){ f[1][1]=f[1][0]=1; for(int i=2;i<=2001;i++){ f[i][0]=f[i][i]=1; for(int j=1;j<i;j++) f[i][j]=(f[i-1][j]+f[i-1][j-1])%mod; } } ll pow_(ll a,ll b){ ll res=1,tmp=a; while(b){ if(b&1) (res*=tmp)%=mod; (tmp*=tmp)%=mod; b/=2; } return res; } int main(){ init();int n,m; while(~scanf("%d%d",&n,&m)){ ll ans=1; (ans*=f[n+m+1][m])%=mod; (ans*=f[n+m][m])%=mod; (ans*=pow_(m+1,mod-2))%=mod; printf("%lld\n",ans); } return 0; }