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:
As the result can be very large, you should print it modulo 109+7109+7.
The only line contains two integers nn and mm (1≤n≤10001≤n≤1000, 1≤m≤101≤m≤10).
Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.
input
2 2
output
5
input
10 1
output
55
input
723 9
output
157557417
In the first test there are 55 suitable arrays:
#include
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;
}