当前位置:网站首页>ARC117E零和范围2
ARC117E零和范围2
2022-07-30 13:41:00 【Heart is cold month】
ARC117E Zero-Sum Ranges 2
Converts an interval sum of zeros to a prefixed sum equal,Something like this:

The answer is obviously the number of layers per layer k k k, k ( k − 1 ) 2 \frac{k(k-1)}{2} 2k(k−1) 的和.
Consider going from top to bottom in layers DP,Note that the positions where the prefix sum is equal are necessarily not adjacent,And there is a peak or pit in the middle of both positions,The pit indicates that the next layer is required.
记 f i , j , k f_{i,j,k} fi,j,k Indicates that there is currently available from top to bottom i i i 个数,The equal pairs formed have j j j 个,The holes to be filled are k k k 个.
考虑转移,Enumerate the next layer to add 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(According to the plug-in method).
Enumerate the variables and merge the upper and lower bounds of zero.
时间复杂度 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;
}
边栏推荐
- 【Advanced Mathematics】【7】Double Integral
- el-table中el-table-column下的操作切换class样式
- ARC117E Zero-Sum Ranges 2
- 电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
- 剑指 Offer 05. 替换空格
- “12306” 的架构到底有多牛逼
- jsArray array copy method performance test 2207300040
- Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
- 【23考研】408代码题参考模板——顺序表
- dolphinscheduler simple task definition and complex cross-node parameter transfer
猜你喜欢
随机推荐
shell 编程规范与变量
CF780G Andryusha and Nervous Barriers
学习笔记——七周成为数据分析师《第一周:数据分析思维》
Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
Synology system installation related file sharing
二手手机销量突破3亿部,与降价的iPhone夹击国产手机
pytorch学习记录(六):循环神经网络 RNN & LSTM
grep时排除指定的文件和目录
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
一本通循环结构的程序设计第一章题解(1)
[PostgreSQL] - Storage structure and cache shared_buffers
Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
无代码开发平台应用可见权限设置入门教程
Lake storehouse which electricity (2) of the project: project using technology and version and the environment
数据中台建设(五):打破企业数据孤岛和提取数据价值
jsArray数组复制方法性能测试2207292307
UPC2022暑期个人训练赛第19场(B,P)
【VMware虚拟机安装mysql5.7教程】
ARC115F Migration
How to migrate the device data connected by RTSP of EasyCVR platform to EasyNVR?









