当前位置:网站首页>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;
}
边栏推荐
- 666666
- These critical programs are missing or too old: ma
- Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
- jsArray array copy method performance test 2207292307
- Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
- 【软考软件评测师】自动化测试章节下篇
- The path to uniting the programmer: "titles bucket" to the highest state of pragmatic
- “封号斗罗” 程序员修炼之道:通向务实的最高境界
- 戴墨镜的卡通太阳SVG动画js特效
- CF780G Andryusha and Nervous Barriers
猜你喜欢
【高等数学】【7】二重积分
The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism
Self-tuning PID self-tuning control 】 【
【VMware虚拟机安装mysql5.7教程】
树形dp小总结(换根,基环树,杂七杂八的dp)
外包干了七年,废了。。。
el-table中el-table-column下的操作切换class样式
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
数据中台建设(五):打破企业数据孤岛和提取数据价值
leetcode207.课程表(判断有向图是否有环)
随机推荐
自从外包干了四年,基本废了...
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD
“封号斗罗” 程序员修炼之道:通向务实的最高境界
[ARC092B] Two Sequences
canvas彩虹桥动画js特效
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
curl 执行脚本时传递环境变量与参数
Markdown 3 - 流程图表
外包干了七年,废了。。。
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
一本通循环结构的程序设计第一章题解(1)
高性能数据访问中间件 OBProxy(三):问题排查和服务运维
The path to uniting the programmer: "titles bucket" to the highest state of pragmatic
R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
[VMware virtual machine installation mysql5.7 tutorial]
CF338E Optimize!
程序员修炼之道:务以己任,实则明心——通向务实的最高境界
12、 学习MySQL 排序