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<bits/stdc++.h>
#define LL long long
#define pa pair<int,int>
#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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值