Educational Codeforces Round 80 (Rated for Div. 2) C题

Two Arrays

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.


题目大致意思是让你取m个数组成数组a(不是递减),取m个数组成数组b(不是递增),m个数可以相等;

首先,我们把题目转为为取2*m个数组成数组c(不是递减);我们只要计算数组c的个数就行;

从1-n个中取2*m个数,还要保证不递减,可以想到dp[i][j], i 表示以 i 开头的数组, j 表示 i 后面的 0 的个数,dp[1][2] 相当于 1** ,也就是以 1 开头,组成数组长为 3 的不递减数组个数;

所以dp[i][j]=sum(dp[i][j-1]+dp[i+1][j-1]+…+dp[n][j-1]);

代码:

#include
#define LL long long
#define pa pair
#define lson k<<1
#define rson k<<1|1
#define inf 0x3f3f3f3f
//ios::sync_with_stdio(false);
using namespace std;
const int N=200100;
const int M=1000100;
const LL mod=1e9+7;
LL dp[1100][100];
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) dp[i][0]=1LL;
	for(int i=1;i<=2*m;i++){
		for(int j=1;j<=n;j++){
			for(int k=j;k<=n;k++){
				dp[j][i]+=dp[k][i-1];
				dp[j][i]%=mod;
			}
		}
	}
	LL sum=0LL;
	for(int i=1;i<=n;i++){
		sum+=dp[i][2*m-1];
		sum%=mod;
	}
	cout<<sum<<endl;
	return 0;
}

你可能感兴趣的:(#,codeforces上分记录,#,线性dp)