当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
The path to uniting the programmer: "titles bucket" to the highest state of pragmatic
SQL 改写系列七:谓词移动
打破原则引入SQL,MongoDB到底想要干啥???
树形dp小总结(换根,基环树,杂七杂八的dp)
What is the level of Ali P7?
05 | 后台登录:基于账号密码的登录方式(下)
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
Self-tuning PID self-tuning control 】 【
学习笔记——七周成为数据分析师《第一周:数据分析思维》
OFDM 十六讲 3- OFDM Waveforms
TaskDispatcher源码解析
[C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向后移动一天(设置参数n为负值)
SQL 26 calculation under 25 years of age or older and the number of users
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
ES6 Set与Map是什么,如何使用
The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism
ARC115F Migration








