There are two count codeforces 1288C constraint array dp

Title link https://codeforces.com/contest/1288/problem/C
Title effect:
there are two arrays of length m a, b
values in the array are 1-n.
Here Insert Picture Description

Q satisfying array (a, b) is below the number of several conditions:
1. The length of the array is equal to two m
2. each element of each array is the integer-n-. 1
3. For any indexes 1-n, there is A [I] <= B [I]
4.a array in a non-descending order;
5.b sorted array in a non-ascending order.
The results can be very large, you should print it modulo. 10 ^ 7 + 9

Here I have strong views on non-descending word, sb topic and people.
Translation of non-descending order.
Gives the understanding that:! (Descending)
while subject means: not strictly descending is a [1]> = a [ 2]> = a [3]> = ...> = a [n].
Ha ha!

Then the observation can be found:
Here Insert Picture Description
respectively dp number AB array of programs, enumerate a last bit of it. a [n]> = a [ b].

Of course, we flipped it around b, on the back of a. It is a length of 2m of non-strictly decreasing sequence.
Here Insert Picture Description

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int mod=1e9+7;
 
LL dp[25][10005];
int main(){
 
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++){
        dp[1][i]=1;
    }
    for(int i=2; i<=2*m; i++){
        for(int j=1; j<=n; j++){
            for(int k=j; k>=1; k--){
                dp[i][j]+=dp[i-1][k];
                dp[i][j]%=mod;
            }
        }
    }
    LL ans=0;
    for(int i=1 ;i<=n; i++){
        ans+=dp[2*m][i];
        ans%=mod;
    }
    printf("%lld\n", ans);
 
    return 0;
}
Published 374 original articles · won praise 22 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_21433411/article/details/103989660