Two Arrays

C. Two Arrays

\ (dp [i] [j ] \) expressed \ (J \) range of each number of the number of \ (1 ~ i \) a number of non-descending time Species, because the data range of n and m is not large, soon be able to obtain a value for each memory search.

Look at the condition \ ((A, B) \) , \ (A \) non-decreasing sequence \ (B \) non-increasing sequence, so \ (B \) is the last of a number greater than or equal \ ( a \) the last number is a necessary and sufficient condition, we only need to traverse \ (a \) last number can be the answer, for example, when (a \) \ the last time a number is 3, this part of the answer should be \ ((DP [. 3] [m] -dp [2] [m]) * DP [+. 1. 3-n-] \) , brackets is \ (a \) number (using inclusion and exclusion species principle), outside the parenthesis is \ (B \) , since \ (B \) in the range of \ (. 3 ~ n-\) , which are arranged in several of \ (1 ~ (n-3 + 1) \) arranged the same number of species.

Hand over the sample carefully to find the law

Code:

// Created by CAD on 2020/1/15.
#include <bits/stdc++.h>
#define mst(name, value) memset(name,value,sizeof(name))
#define ll long long
using namespace std;

const int maxn=1005;
const int mod=1e9+7;
ll dp[maxn][15];
ll dfs(ll m,ll n)
{
    if(~dp[n][m]) return dp[n][m];
    if(m==1) return dp[n][m]=n;
    ll ans=0;
    for(int i=1;i<=n;++i)
        ans=(ans+dfs(m-1,i))%mod;
    return dp[n][m]=(ans+mod)%mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    mst(dp,-1);
    int n,m;    cin>>n>>m;
    ll ans=0;
    for(int i=1;i<=n;++i)
        ans=(ans+(dfs(m,i)-dfs(m,i-1))*dfs(m,n-i+1)%mod+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/CADCADCAD/p/12196014.html