当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

cpu / CS 和 IP

TaskDispatcher源码解析

Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
![[VMware virtual machine installation mysql5.7 tutorial]](/img/eb/4b47b859bb5695c38d48c8c01c9da0.png)
[VMware virtual machine installation mysql5.7 tutorial]

PyQt5快速开发与实战 8.6 设置样式

人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准

shell script flow control statement

电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM

激光雷达点云语义分割论文阅读小结

What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
随机推荐
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
shell 编程规范与变量
【软考软件评测师】自动化测试章节下篇
SQL 改写系列七:谓词移动
SQL 26 calculation under 25 years of age or older and the number of users
qq udp tcp机制
“封号斗罗” 程序员修炼之道:通向务实的最高境界
激光雷达点云语义分割论文阅读小结
Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
缓存一致性
高性能数据访问中间件 OBProxy(三):问题排查和服务运维
Composer安装方式
58. 最后一个单词的长度
机器学习——特征选择
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
shell脚本流程控制语句
12、 学习MySQL 排序
cpu / CS 和 IP
el-table中el-table-column下的操作切换class样式
EasyNVS cloud management platform function reconstruction: support for adding users, modifying information, etc.