当前位置:网站首页>ARC117E Zero-Sum Ranges 2
ARC117E Zero-Sum Ranges 2
2022-07-30 13:17:00 【心怀凉月】
ARC117E Zero-Sum Ranges 2
将区间和为零转换为前缀和相等,类似于这种东西:

答案显然是每层个数 k k k, k ( k − 1 ) 2 \frac{k(k-1)}{2} 2k(k−1) 的和。
考虑按层从上往下 DP,注意到前缀和相等的位置必然不相邻,并且两个位置中间都是一个峰或者坑,坑表示下一层必填。
记 f i , j , k f_{i,j,k} fi,j,k 表示从上往下当前有 i i i 个数,形成的相等对有 j j j 个,要填的坑有 k k k 个。
考虑转移,枚举下一层添加 x x x 个数: f i , j , k → f i + x , j + x ( x − 1 ) 2 , x − ( k + 2 ) f_{i,j,k}\to f_{i+x,j+\frac{x(x-1)}{2},x-(k+2)} fi,j,k→fi+x,j+2x(x−1),x−(k+2),系数为 C x − 1 k + 1 C_{x-1}^{k+1} Cx−1k+1(根据插板法)。
枚举一下变量合并零界上下即可。
时间复杂度 O ( n 5 ) \mathcal O(n^5) O(n5)。
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
int n, k, f[105][1005][105], c[105][105];
signed main() {
n = read(), k = read();
for (int i = 0; i <= n + 1; ++i) {
c[i][0] = c[i][i] = 1;
for (int j = 1; j <= i; ++j) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
for (int i = 1; i <= 2 * n + 2; ++i) f[i][i * (i - 1) / 2][i - 1] = 1;
for (int i = 0; i <= 2 * n + 2; ++i)
for (int j = 0; j <= n * n + 1; ++j)
for (int l = 0; l <= n + 2; ++l) {
if (f[i][j][l] == 0) continue;
for (int x = l + 2; x <= 2 * n + 2; ++x) {
int nxt = j + x * (x - 1) / 2;
if (nxt > k) break;
f[i + x][nxt][x - (l + 2)] += f[i][j][l] * c[x - 1][l + 1];
}
}
ll ans = f[2 * n + 1][k][0];
for (int i = 0; i <= 2 * n + 1; ++i)
for (int j = 0; j <= k; ++j)
for (int l = 1; l <= n; ++l)
ans += f[i][j][l] * f[2 * n + 1 - i][k - j][l - 1];
write(ans), he;
return 0;
}
边栏推荐
- R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
- 逻辑漏洞----权限类漏洞
- 666666
- Apache Log4j2漏洞
- dolphinscheduler simple task definition and complex cross-node parameter transfer
- 深度操作系统DeepinOS安装步骤和MySQL安装测试
- TaskDispatcher源码解析
- What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
- js人均寿命和GDP散点图统计样式
- 【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求
猜你喜欢
随机推荐
js男女身高体重关系图
创意loadingjs特效小点跳跃动画
20220729 Securities, Finance
腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
【高等数学】【7】二重积分
cpu / CS 和 IP
datax enables hana support and dolphinscheduler enables datax tasks
BUUCTF刷题十一道(06)
Anaconda\Scripts\pip-script.py is not present ? 解决方案
no matching host key type found. Their offer: ssh-rsa
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
缓存一致性
Markdown 1 - 图文音视频等
Self-tuning PID self-tuning control 】 【
浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
CV-Model【2】:MobileNet v1
EasyNVS cloud management platform function reconstruction: support for adding users, modifying information, etc.
How to migrate the device data connected by RTSP of EasyCVR platform to EasyNVR?
Current and voltage acquisition module DAM-6160
【23考研】408代码题参考模板——顺序表








