Two Arrays(sdau19训练2)

【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} am1 a m − 2 a_{m-2} am2 ≥…>= 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浅梦曾倾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值