[ARC232E] Doubling
Genius_Star · · 题解
或许更好的阅读体验。
区区题,这题 *3600???
思路:
考虑每个位置操作的次数
对于所有满足这个条件的
有一个显然的
看起来状态数就不太好优化,考虑生成函数,你发现一维生成函数也是不太好转移的,刚好
初始
这个递推式子一点也不漂亮,想了挺久感觉不太能求封闭形式;然后你可以注意到一个关键性质,这个递推式中第一项始终是
使用上面的递推式子:
然后你还要算
于是你要进行
完整代码:
#include<bits/stdc++.h>
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
const int N = 21, M = 2.5e5 + 10, mod = 998244353;
inline ll read(){
ll 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 << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
inline void write(ll x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline void getadd(int &x, int y){
x = (x + y >= mod) ? (x + y - mod) : (x + y);
}
inline int add(int x, int y){
return (x + y >= mod) ? (x + y - mod) : (x + y);
}
inline void getdec(int &x, int y){
x = (x < y) ? (x - y + mod) : (x - y);
}
inline int dec(int x, int y){
return (x < y) ? (x - y + mod) : (x - y);
}
int n, K;
int poww[N], A[N];
class poly{
public:
int a[M];
inline int& operator[](int i){
return a[i];
}
inline void getp(int p){
for(int i = p; i <= K; ++i)
getadd(a[i], a[i - p]);
}
}F[N][N];
int main(){
n = read(), K = read();
for(int i = 0; i < n; ++i){
A[i] = read();
poww[i] = 1 << i;
// cout << i << ' ' << poww[i] << '\n';
}
poww[n] = 1 << n;
for(int i = 0; i < n; ++i){
int p = poww[i + 1] - 2;
for(int j = 0; j <= A[0]; ++j){
int x = j * (p + 1);
if(x > K)
break;
F[0][i][x] = 1;
// cout << i << ' ' << x << '\n';
}
}
for(int i = 1; i < n; ++i){
for(int k = 0; k < n - i; ++k){
int p = poww[k + 1] - 2;
ll x = 1ll * (p + 1) * (A[i] + 1);
for(int j = 0; j <= K; ++j){
F[i][k][j] = F[i - 1][0][j];
if(j >= x)
getdec(F[i][k][j], F[i - 1][k + 1][j - x]);
}
F[i][k].getp(p + 1);
}
}
for(int i = 1; i <= K; ++i){
write(F[n - 1][0][i]);
putchar(' ');
}
return 0;
}