C. Two Arrays

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;
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章