E. Natasha, Sasha and the Prefix Sums

Posted liulex

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E. Natasha, Sasha and the Prefix Sums相关的知识,希望对你有一定的参考价值。

给定n个 1 m个 -1的全排

求所有排列的$f(a)=max(0,max_1il∑_j=1^ia_j)$之和

组合数,枚举

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MOD = 998244853;

int n, m;
ll C[4002][4002];
ll sum;
ll realSum;
ll ans;

void init()

    for(int i=0; i<=4000; i++) C[i][0] = C[i][i] = 1;
    for(int i=1; i<=4000; i++)
    
        for(int j=1; j<i; j++)
        
            C[i][j] = (C[i-1][j-1] + C[i-1][j])%MOD;
        
    


int main()

    init();
    scanf("%d%d", &n, &m);
    for(int i=n; i>=1 && i>=n-m; i--)///枚举前缀和最大为i时
    
        sum = (C[n+m][n-i] - realSum + MOD) % MOD;///前缀和最大为i的排列个数
        ans = (ans+(sum * i) % MOD)%MOD;
        realSum = (realSum + sum)%MOD;
    
    printf("%lld\n", ans);

 

以上是关于E. Natasha, Sasha and the Prefix Sums的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #581 (Div. 2) E. Natasha, Sasha and the Prefix Sums

Codeforces Round #581 (Div. 2) E. Natasha, Sasha and the Prefix Sums

[CF1204E]Natasha,Sasha and the Prefix Sums 题解

CF1204E Natasha, Sasha and the Prefix Sums

Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学

CF1024E Natasha, Sasha and the Prefix Sums——DP/数学(组合数)