I Will Like Matrix!【DP】

Description–

All positions in a matrix of n * m A is 0 or 1, respectively, filled, several requirements must be met filled Ai, j ≤ Ai, j + 1 and
Ai, j ≤ Ai + 1, j. Asked a total of how many different matrix, and the answer to 1, 000, 000, 007 modulo.


Input–

Total line contains two integers n and m.

Output–

ANS total line contains an integer, represents 000 000, the number of values ​​of the matrix die 1,, 007.


Sample Input–

2 2

Sample Output–

6


Notes -

For 60% of the data: n, m, k ≤ 300
to 100% of the data: n, m, k ≤ 5000


Problem-solving ideas -

a [i] [j] expressed as (i, j) is the upper left corner to (n, m) is the lower right corner of the matrix has a [i] [j] different matrices.
a [i] [j] = a [i + 1] [j] + a [i] [j + 1]


Code -

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,a[5005][5005];
int main()
{
	scanf("%d%d",&n,&m);
	a[n][m]=2;//赋初值
	for (int i=n-1;i>=1;--i)
	  a[i][m]=a[i+1][m]+1;
	for (int i=m-1;i>=1;--i)
	  a[n][i]=a[n][i+1]+1;
	for (int i=n-1;i>=1;--i)
	  for (int j=m-1;j>=1;--j)
	    a[i][j]=(a[i+1][j]+a[i][j+1])%1000000007;
	printf("%d",a[1][1]);
	
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_43654542/article/details/90699270