C. Two Arrays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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
2 2
output
5
input
10 1
output
55
input
723 9
output
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].
Solution
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 10;
const int mod = 1e9 + 7;
int dp[11][maxn];
inline const int read()
{
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
int main()
{
int n = read(), m = read(), res = 0;
for (int i = 1; i <= n; i++) dp[1][i] = 1;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= j; k++)
dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod;
for (int i = 1; i <= n; i++)
{
ll sum = 0;
for (int j = 1; j <= n - i + 1; j++)
sum = (sum + dp[m][j]) % mod;
res = (res + sum * dp[m][i] % mod) % mod;
}
printf("%d\n", res);
return 0;
}