【Question】
You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b) such that:
- the length of both arrays is equal to m;
- each element of each array is an integer between 1 and n (inclusive);
- ai≤bi for any index i from 1 to m;
- array a is sorted in non-descending order;
- array b is sorted in non-ascending order.
As the result can be very large, you should print it modulo 1 0 9 10^9 109+7.【Input】
The only line contains two integers n and m(1 ≤ \leq ≤ n ≤ \leq ≤ 1000,1 ≤ \leq ≤ m ≤ \leq ≤ 10).
【Output】
Print one integer – the number of arrays a and b satisfying the conditions described above modulo 1 0 9 10^9 109+7.
【Examples】
Input
2 2
Output
5
Input
10 1
Output
55
Input
723 9
Output
157557417
【思路】
题意:
a数组是不递减的,b数组是不递增的,且 a i a_i ai <= b i b_i bi,即 b 1 b_1 b1 ≥ b 2 b_2 b2 ≥ b 3 b_3 b3≥ … >= b m b_m bm ≥ a m a_m am ≥ a m − 1 a_{m-1} am−1 ≥ a m − 2 a_{m-2} am−2 ≥…>= a 1 a_1 a1 .
相当于构建了一个长为2*m的不递增序列。
思路:
其实这道题是一道很明显的dp题,但却花了我很长时间理解,关键就在于把题意中给的数据的处理,即处理成一个不递增序列
【源代码】
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;
#include<stack>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#define ll long long
//struct node { double cost; LL v; double x; }a[100];
//bool cmp(node a, node b){ return a.x < b.x;}
string a;
//int b[110];
ll mod = 1e9 + 7;
ll dp[30][11000];
int main()
{/*确定了不递增序列,只需要逐位添加数字即可*/
int n, m;//n为最大值,m长度
cin >> n >> m;
m *= 2;
for (int i = 1; i <= n; i++)//初始化
dp[1][i] = 1;
for (int i = 2; 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;//自身加上比j小的数的种类
ll ans = 0;
for (int i = 1; i <= n; i++)
ans = (ans + dp[m][i]) % mod;
cout << ans << endl;
return 0;
}