【数学】Natasha, Sasha and the Prefix Sums(CF1204E)
正题
luogu
CF1204E
题目大意
给出序列a,由n个1和m个-1组成,设 f 为最大前缀和和0的最大值,问全排列的 f 之和
解题思路
可以问题转换到平面图上,把1看作往上走,-1看作往下走
那么问题就变成了求 (0,0) 到 (n+m,n-m) 所有路径的y坐标最大值之和
可以考虑枚举最大y坐标,然后求方案数
先考虑如何强制经过 y=i 这条线,即到达这个高度(如果起点终点在这条线的异侧就不用操作了)
可以把 (0,0) 关于 y=i 对称,把 (0,2i) 走到 (n+m,n-m) 的路径后把 (0,2i) 到第一个经过 y=i 的点这段路径对称回来,就得到了一条强制经过 y=i 的路径,但是可能过了 y=i,容斥以下即可
综上方案数为
S={(n+mn)(i≤n)(n+mn−i)(i>n)S=\Large{\left\{\begin{matrix} \binom{n+m}{n} \quad (i\leq n)\\ \binom{n+m}{n-i} \quad (i>n)\end{matrix}\right.}S=⎩⎨⎧(nn+m)(i≤n)(n−in+m)(i>n)
code
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define mod 998244853
#define N 100000
using namespace std;
ll ans,n,m,q[N],qpr[N],pr[N];
ll C(ll n,ll m)
{return pr[n]*qpr[n-m]%mod*qpr[m]%mod;
}
ll get(ll k)
{if(k<=n-m)return C(n+m,n);else return C(n+m,n-k);
}
int main()
{scanf("%lld%lld",&n,&m);qpr[0]=pr[0]=q[1]=qpr[1]=pr[1]=1;for(int i=2;i<=n+m;++i){q[i]=mod-mod/i*q[mod%i]%mod;qpr[i]=qpr[i-1]*q[i]%mod;;pr[i]=pr[i-1]*i%mod;}for(int i=1;i<=n;++i)(ans+=(get(i)-get(i+1)+mod)%mod*i%mod)%=mod;printf("%lld",ans);return 0;
}
【数学】Natasha, Sasha and the Prefix Sums(CF1204E)相关推荐
- 【题解】【数组】【Prefix Sums】【Codility】Genomic Range Query
A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper- ...
- 【CodeForces - 1150C】Prefix Sum Primes(思维)
题干: We're giving away nice huge bags containing number tiles! A bag we want to present to you contai ...
- Gradient Boosting, Decision Trees and XGBoost with CUDA ——GPU加速5-6倍
xgboost的可以参考:https://xgboost.readthedocs.io/en/latest/gpu/index.html 整体看加速5-6倍的样子. Gradient Boosting ...
- Too Many Segments (hard version) CodeForces - 1249D2(贪心+容器vector+set)
题目 给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置. The only difference between easy and hard version ...
- [Swift]LeetCode1044. 最长重复子串 | Longest Duplicate Substring
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- 2022 China Collegiate Programming Contest (CCPC) Guilin Site - C. Array Concatenation
C. Array Concatenation time limit per test1 second memory limit per test512 megabytes inputstandard ...
- 1732C1 - Sheikh (Easy version)
Note that f(l,r)≤f(l,r+1). To prove this fact, let's see how the sum and xor change when the element ...
- Codeforces Round #827 (Div. 4) E. Scuza
Codeforces Round #827 (Div. 4) E. Scuza 前缀和 前缀和 前缀和 + 二分 二分 二分 Let's compute the prefix sums of the ...
- 2021UPC个人训练赛第47场
个人训练赛第47场 A: 加工零件(最短路) 问题 A: 加工零件时间限制: 1 Sec 内存限制: 128 MB 题目描述 凯凯的工厂正在有条不紊地生产一种神奇的零件,神奇的零件的生产过程自然也很神 ...
最新文章
- C++/C++11中引用的使用
- sql调用web服务
- Mysql常用基础命令操作实战
- openshift_在OpenShift上托管的WildFly实例上进行Arquillian测试
- 1 Hadoop简介
- Perl的浅拷贝和深度拷贝
- WSGI Application/Framework
- 递推公式与递归退出的条件
- 单精度浮点数(float)加法计算出错
- InoReader——网页无法打开
- import torch -- AttributeError: module ‘typing‘ has no attribute ‘_SpecialForm‘
- JSP实现注册并显示信息
- do while循环
- python3.7 openpyxl 在excel单元格中写入数据
- 新概念c语言教程答案,新概念C语言能力教程练习答案.doc
- Java修炼之凡界篇 筑基期 第02卷 语法 番外1 原码 反码 补码
- 3.7 百分比堆积柱形图
- 关于《无货源开店已确认违法》新闻稿说明
- 我利用Python画了这十个图,收到了公司小姐姐20封情书
- 讲英语者的10个成功秘诀
热门文章
- s6730堆叠_不再只是堆叠硬件 ivvi S6全方位评测
- python tuple args_Python基本数据类型之tuple
- 数字图像处理王伟强_深度学习主导下,还有必要学数字图像处理?
- aspose excel中文文档_除了VBA,还有哪些编程语言可以操作Excel文件?
- 提高python执行效率_提升Python程序运行效率的6个方法
- 循环遍历多层json_面试官:JSON.stringify() 实现深拷贝有什么问题
- leetcode429. N 叉树的层序遍历(层序遍历05)
- [Redis6]发布和订阅
- [SpringBoot2]ajax函数中data参数的数据设置方式
- 上元节的灯会(灭)-区间dp