You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that:
- the length of both arrays is equal to mm;
- each element of each array is an integer between 11 and nn (inclusive);
- ai≤biai≤bi for any index ii from 11 to mm;
- array aa is sorted in non-descending order;
- array bb is sorted in non-ascending order.
As the result can be very large, you should print it modulo 109+7109+7.
Input
The only line contains two integers nn and mm (1≤n≤10001≤n≤1000, 1≤m≤101≤m≤10).
Output
Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.
Examples
input
Copy
2 2
output
Copy
5
input
Copy
10 1
output
Copy
55
input
Copy
723 9
output
Copy
157557417
Note
In the first test there are 55 suitable arrays:
- a=[1,1],b=[2,2]a=[1,1],b=[2,2];
- a=[1,2],b=[2,2]a=[1,2],b=[2,2];
- a=[2,2],b=[2,2]a=[2,2],b=[2,2];
- a=[1,1],b=[2,1]a=[1,1],b=[2,1];
- a=[1,1],b=[1,1]a=[1,1],b=[1,1].
题意:
给出2个整数n,m,然后让你构建2个数列a,b,数列长度都为m,每个a[i],b[i]都属于[1,n],数列a非递减,数列b非递增,b[i]>=a[i],问你有多少种构造方法。
思路:
很明显是一道DP题,看代码把= =
code:
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL MOD = 1e9+7;
LL n,m,dp1[1001][11],dp2[1001][11],ans = 0;
int main()
{
cin>>n>>m;
for(int i=1; i <= n; i++)
{
dp1[i][1] = 1;
dp2[i][1] = 1;
}
for(int i = 2; i <= m; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= j;k++)
dp1[j][i] = (dp1[j][i]+dp1[k][i-1])%MOD;
for(int i = 2; i <= m; i++)
for(int j = 1; j <= n; j++)
for(int k = j; k <= n; k++)
dp2[j][i] = (dp2[j][i]+dp2[k][i-1])%MOD;
for(int i=1; i <= n; i++)
for(int j=i; j <= n; j++)
ans = (ans+dp1[i][m]*dp2[j][m])%MOD;
cout<<ans<<endl;
return 0;
}