C. Two Arrays(区间dp)

You are given two integers nn and mm. Calculate the number of pairs of arrays (a,b)(a,b) such that:

  • the length of both arrays is equal to mm;

  • each element of each array is an integer between 11 and nn (inclusive);

  • ai≤biai≤bi for any index ii from 11 to mm;

  • array aa is sorted in non-descending order;

  • array bb is sorted in non-ascending order.

As the result can be very large, you should print it modulo 109+7109+7.

Input

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

Output

Print one integer – the number of arrays aa and bb satisfying the conditions described above modulo 109+7109+7.

Examples

input

Copy

2 2

output

Copy

5

input

Copy

10 1

output

Copy

55

input

Copy

723 9

output

Copy

157557417

Note

In the first test there are 55 suitable arrays:

  • a=[1,1],b=[2,2]a=[1,1],b=[2,2];

  • a=[1,2],b=[2,2]a=[1,2],b=[2,2];

  • a=[2,2],b=[2,2]a=[2,2],b=[2,2];

  • a=[1,1],b=[2,1]a=[1,1],b=[2,1];

  • a=[1,1],b=[1,1]a=[1,1],b=[1,1].

给定两个整数n和m。计算数组(a,b)对的数量,使:

两个数组的长度都等于m;

每个数组的每个元素都是1到n(含)之间的整数;

对于从1到m的任意指标I, Ai≤bi;

数组a按非降序排序;

数组b按非升序排序。

由于结果可能非常大,所以应该对109+7取模进行打印。

输入

唯一一行包含两个整数n和m(1≤n≤1000,1≤m≤10)。

输出

打印一个整数-满足上述条件的数组a和b的个数对109+7取模。

由上边的关系可以得出a1<=…ai<=…am<=bm…<=bi<=…b1.

所以问题就转化为求一个长度为2m的不下降序列的个数

所以我们可以用区间dp

dp数组为二位数组

第一位维表示数组大小

第二维表示结尾元素

状态转移方程为

dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
const int N = 1e5+10;
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int dp[40][1100];
void solve()
{
    int n,m;
    cin>>n>>m;
    m*=2;
    for(int i=1;i<=n;i++)
    {
        dp[1][i]=1;
    }
    int sum=0;
    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;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        sum+=dp[m][i];
        sum%=mod;
    }
    cout<<sum<<endl;
}
signed main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值