当前位置:网站首页>[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
2022-04-23 10:22:00 【DD(XYX)】
Topic


Answer key
This range can tell us a lot of information , For example, the number of prime numbers , namely , The square has the most prime numbers in the range 14 individual .
This reminds us of , After each number prime factor is decomposed Does not belong to the former 14 The prime factor of a prime number At most one .
and , We can compress this range again , because 43 × 47 > 2000 43\times47>2000 43×47>2000 , So each number Does not belong to the former 13 The prime factor of a prime number most A kind of , That is, there is either only one , Or 4 3 2 43^2 432 , There is only one .
So we can put the front 13 Whether a prime number exists or not , Then make a similar knapsack DP The algorithm of . How to satisfy 13 The prime number after two ? We can group according to the largest prime factor , When there is a 13 A prime number after P P P The condition of existence , Just put the... Of each state Total number of schemes ( Consider 13 The number of schemes of all prime numbers after ) remove 【 P P P Number of group options 】, And ride on 【 P P P Number of schemes selected by at least one group 】. because 【 P P P Number of group options 】 yes 2 The power of , So there must be an inverse element .
This special Backpack DP The transfer of , It can be used FWT Convolution optimization . In particular , We can count the number of schemes first DP The array is preprocessed by positive transformation , Then the query is modified linearly , The last inverse transformation to find the answer .
Time complexity O ( 2 13 ∑ c i + m ⋅ 2 13 ⋅ 13 ) O(2^{13}\sum c_i+m\cdot2^{13}\cdot13) O(213∑ci+m⋅213⋅13) .
CODE
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<vector>
#include<random>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 2005
#define LL long long
#define DB double
#define ENDL putchar('\n')
#define lowbit(x) (-(x) & (x))
#define FI first
#define SE second
inline int xchar() {
static const int maxnn = 1000000;
static char b[maxnn];
static int pos = 0,len = 0;
if(pos == len) pos = 0,len = fread(b,1,maxnn,stdin);
if(pos == len) return -1;
return b[pos ++];
}
//#define getchar() xchar()
inline LL read() {
LL f=1,x=0;int s = getchar();
while(s<'0'||s>'9') {
if(s<0)return -1;if(s=='-')f=-f;s=getchar();}
while(s>='0'&&s<='9') {
x=(x<<3)+(x<<1)+(s^48);s = getchar();}
return f * x;
}
void putpos(LL x) {
if(!x) return ;
putpos(x/10); putchar((x%10)^48);
}
void putnum(LL x) {
if(!x) {
putchar('0');return ;}
if(x < 0) putchar('-'),x = -x;
return putpos(x);
}
inline void AIput(LL x,int c) {
putnum(x);putchar(c);}
const int MOD = 998244353;
const int iv2 = (MOD+1)/2;
int n,m,s,o,k;
int pw[1000005],ip[1000005];
int p[310],f[MAXN],cnt,id[MAXN];
void sieve(int n) {
for(int i = 2;i <= n;i ++) {
if(!f[i]) p[++ cnt] = i,id[i] = cnt;
for(int j = 1;j <= cnt && i*p[j] <= n;j ++) {
f[i*p[j]] = 1; if(i % p[j] == 0) break;
}
}return ;
}
int ct[MAXN];
int s0[310][1<<13|5],s1[310][1<<13|5];
inline void MD(int &x) {
if(x>=MOD)x-=MOD;}
void DWTOR(int *s,int n) {
for(int k = 2;k <= n;k <<= 1) {
for(int j = 0;j < n;j += k) {
for(int i = j;i < j+(k>>1);i ++) {
MD(s[i+(k>>1)] += s[i]);
}
}
} return ;
}
void IDWTOR(int *s,int n) {
for(int k = n;k > 1;k >>= 1) {
for(int j = 0;j < n;j += k) {
for(int i = j;i < j+(k>>1);i ++) {
MD(s[i+(k>>1)] += MOD-s[i]);
}
}
} return ;
}
int tmp[1<<13|5];
int A[1<<13|5];
int main() {
// freopen(...
sieve(2000);
n = read();
pw[0] = 1; ip[0] = 1;
for(int i = 1;i <= n;i ++) {
MD(pw[i] = (pw[i-1]<<1));
ip[i] = ip[i-1] *1ll* iv2 % MOD;
ct[read()] ++;
}
int tp = 1<<13;
for(int i = 0;i < tp;i ++) tmp[i] = 1;
for(int i = 0;i <= cnt;i ++) {
for(int j = 0;j < tp;j ++) s0[i][j] = 1,s1[i][j] = 1;
}
for(int i = 1;i <= 2000;i ++) {
int nn = i;
int ls = 0,S = 0;
for(int j = 1;j <= cnt && p[j] <= nn;j ++) {
if(nn % p[j] == 0) {
if(j <= 13) S |= (1<<(j-1));
ls = j; while(nn % p[j] == 0) nn /= p[j];
}
}
int nm = pw[ct[i]],nm2 = ip[ct[i]];
for(int j = 0;j < tp;j ++) {
if((j&S) == S) {
s0[ls][j] = s0[ls][j] *1ll* nm2 % MOD;
s1[ls][j] = s1[ls][j] *1ll* nm % MOD;
}
}
}
for(int i = 0;i <= cnt;i ++) {
for(int j = 0;j < tp;j ++) {
tmp[j] = tmp[j] *1ll* s1[i][j] % MOD;
MD(s1[i][j] += MOD-1);
}
}
m = read();
for(int i = 1;i <= m;i ++) {
k = read();
for(int j = 0;j < tp;j ++) A[j] = tmp[j];
for(int j = 1;j <= cnt;j ++) f[j] = 0;
int S = 0;
while(k --) {
int x = id[read()];
if(x <= 13) S |= (1<<(x-1));
else f[x] = 1;
}
for(int j = 14;j <= cnt;j ++) {
if(f[j]) {
for(int k = 0;k < tp;k ++) {
A[k] = A[k] *1ll* s0[j][k] % MOD * s1[j][k] % MOD;
}
}
}
IDWTOR(A,tp);
int ans = 0;
for(int j = 0;j < tp;j ++) {
if((j&S) == S) {
MD(ans += A[j]);
}
}
AIput(ans,'\n');
}
return 0;
}
版权声明
本文为[DD(XYX)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231007427462.html
边栏推荐
- DBA common SQL statements (1) - overview information
- Reading integrity monitoring techniques for vision navigation systems - 3 background
- 101. Symmetric Tree
- C#和数据库连接中类的问题
- 链表相交(链表)
- Sim Api User Guide(5)
- Leetcode22:括号生成
- 杰理之更准确地确定异常地址【篇】
- Solution architect's small bag - 5 types of architecture diagrams
- Construction and traversal of binary tree
猜你喜欢

Sim Api User Guide(5)

net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。

2022年广东省安全员A证第三批(主要负责人)考试试题及答案

Solve the problem of installing VMware after uninstalling

Sim Api User Guide(4)

解决方案架构师的小锦囊 - 架构图的 5 种类型

2022茶艺师(初级)考试试题模拟考试平台操作

Operation of 2022 tea artist (primary) test question simulation test platform

第120章 SQL函数 ROUND

Juc并发编程09——Condition实现源码分析
随机推荐
杰理之通常影响CPU性能测试结果的因素有:【篇】
Jerry's more accurate determination of abnormal address [chapter]
24、两两交换链表中的节点(链表)
解决VMware卸载后再安装出现的问题
19、删除链表的倒数第N个节点(链表)
【无标题】
142、环形链表||
JUC concurrent programming 06 -- in-depth analysis of AQS source code of queue synchronizer
通过流式数据集成实现数据价值(5)- 流处理
Realizing data value through streaming data integration (4) - streaming data pipeline
203、移出链表元素(链表)
Ansible playbook syntax and format automate cloud computing
2022年上海市安全员C证考试题库及答案
Net start MySQL MySQL service is starting MySQL service failed to start. The service did not report any errors.
Exercise questions and simulation test of refrigeration and air conditioning equipment operation test in 2022
101. Symmetric Tree
Realizing data value through streaming data integration (5) - stream processing
解决方案架构师的小锦囊 - 架构图的 5 种类型
19. Delete the penultimate node of the linked list (linked list)
Sim Api User Guide(5)