CF1288C-Two Arrays- thinking + dp

Description

You are given two integers n and m. 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 109+7.

Input

The only line contains two integers n and m (1≤n≤1000, 1≤m≤10).

Output

Print one integer – the number of arrays a and b satisfying the conditions described above modulo 109+7.

Sample Input

723 9

Sample Output

157557417

main idea:

1, a sequence of non-decreasing, i.e., a m is a maximum number of
2, non-incremental sequence b, i.e., b m is the smallest number b
3 by a I ≤b I can get a m ≤b m
have the above-mentioned three points can be introduced:
first traversal order of the sequence a, and then reverse traversal sequence b, can get a length of 2 m * non-decreasing sequence of C . (Ie, sequences a and b is connected to tail)

At this point, it is converted to the title satisfying the following conditions required number sequence c:
a length of m * 2
2, c I in the range of [1, n-]
. 3, non-decreasing sequence c

dp resolve this issue:
dp [I] [J] indicates the number of sequences satisfy the following conditions:
1, the length I
2, the first number is J
. 3, non-decreasing sequence

Refer to code!

code show as below:

#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=1100,M=11;
const ll mo=1e9+7;
ll dp[M<<1][N];
int main()
{
	int n,m;
	cin>>n>>m;
	m<<=1;
	for(int i=1;i<=n;i++)
		dp[1][i]=1;
	for(int i=2;i<=m;i++)
		for(int j=n;j>0;j--)
			dp[i][j]=(dp[i][j+1]+dp[i-1][j])%mo;
	ll ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+dp[m][i])%mo;
	cout<<ans<<endl;
	return 0;
}
Published 144 original articles · won praise 135 · views 10000 +

Guess you like

Origin blog.csdn.net/Nothing_but_Fight/article/details/103983854