标签:col c++ atom class mes names row ons msu
给定n个 1 m个 -1的全排
求所有排列的$f(a)=max(0,max_{1≤i≤l}∑_{j=1}^{i}a_{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
标签:col c++ atom class mes names row ons msu
原文地址:https://www.cnblogs.com/liulex/p/11387460.html