当前位置:网站首页>Noip2021 T2 series
Noip2021 T2 series
2022-07-24 13:50:00 【lAWTYl】
Portal :NOIP2021 T2 The sequence
The main idea of the topic
Given integer n , m , k n, m, k n,m,k, And a length of m + 1 m + 1 m+1 A positive integer array of v 0 , v 1 , … , v m v_0, v_1, \ldots, v_m v0,v1,…,vm.
For a length of n n n, Subscript from 1 1 1 Start with no more than m m m A sequence of nonnegative integers { a i } \{a_i\} { ai}, We define its weight as v a 1 × v a 2 × ⋯ × v a n v_{a_1} \times v_{a_2} \times \cdots \times v_{a_n} va1×va2×⋯×van.
When such a sequence { a i } \{a_i\} { ai} Satisfy integer S = 2 a 1 + 2 a 2 + ⋯ + 2 a n S = 2^{a_1} + 2^{a_2} + \cdots + 2^{a_n} S=2a1+2a2+⋯+2an In the binary representation of 1 1 1 No more than k k k when , We think { a i } \{a_i\} { ai} Is a legal sequence .
Calculate all legal sequences { a i } \{a_i\} { ai} The weight sum of 998244353 998244353 998244353 Results of die taking .
analysis
I still vaguely remember the most violent violence in the examination room … Did you get a point qwq
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MOD 998244353
#define MAXN 202
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int k = 0;
int v[MAXN] = {
0 };
int n = 0; int m = 0;
inline int lowbit(int x){
return x & -x;
}
int ans = 0;
int a[MAXN] = {
0 };
void work(){
int S = 0;
for(int i = 1; i <= n; i++) S += pow(2, a[i]);
int cnt1 = 0;
while(S){
S -= lowbit(S); cnt1++;
if(cnt1 > k) return;
}
int temp = 1;
for(int i = 1; i <= n; i++)
temp = (1ll * temp * v[a[i]]) % MOD;
ans = (1ll * ans + temp) % MOD;
}
void dfs(int now){
if(now > n){
work(); return; }
for(int i = 0; i <= m; i++){
a[now] = i;
dfs(now + 1);
a[now] = 0;
}
}
int main(){
n = in; m = in; k = in;
for(int i = 0; i <= m; i++) v[i] = in;
dfs(1);
cout << ans << endl;
return 0;
}
Okay , Now let's look at the normal solution .
Look at this data range , n , m n, m n,m They are all relatively small , So it should not be counting , Then consider d p dp dp. set up f i , j , k , l f_{i, j, k, l} fi,j,k,l Indicates the current processing of i i i position , It has been used j j j Number , front i i i There are k k k individual “ 1 1 1”, And in the i i i For rounding l l l Time .
Then based on this information, we enumerate the current i i i Place x x x individual “ 1 1 1”. We can know the number i + 1 i + 1 i+1 Is it 0 0 0 still 1 1 1. say concretely , We are i i i Bit carry l l l Time , that i + 1 i + 1 i+1 Bit is carried l 2 \frac l2 2l Time . And we let go again x x x individual 1 1 1, So the first i + 1 i + 1 i+1 Bits are carried in total ⌊ l + x 2 ⌋ \lfloor \frac {l+x}2 \rfloor ⌊2l+x⌋ Time . Then we can start from :
f i , j , k , l f_{i, j, k, l} fi,j,k,l
Transferred to the :
f i + 1 , j + x , k + ( ⌊ l + x 2 ⌋ ∧ 1 ) , ⌊ l + x 2 ⌋ f_{i + 1, j + x, k + (\lfloor \frac {l + x}2 \rfloor \land 1), \lfloor\frac {l + x}2 \rfloor} fi+1,j+x,k+(⌊2l+x⌋∧1),⌊2l+x⌋
That's how it's transferred :
f i , j , k , l → f i + 1 , j + x , k + ( ⌊ l + x 2 ⌋ ∧ 1 ) , ⌊ l + x 2 ⌋ f_{i, j, k, l} \to f_{i + 1, j + x, k + (\lfloor \frac {l + x}2 \rfloor \land 1), \lfloor\frac {l + x}2 \rfloor} fi,j,k,l→fi+1,j+x,k+(⌊2l+x⌋∧1),⌊2l+x⌋
Obviously, this cannot be added directly , There are also some coefficients ahead . The first obvious coefficient is v i x v_{i}^x vix This is where I am i i i Bit plus x x x individual i i i Contribution to the answer , Then there is another coefficient, which is the number of schemes , That is to say, there are still n − j n - j n−j Select from the number x x x A for i i i The number of solutions is ( n − j x ) \begin{pmatrix} n - j \\ x \end{pmatrix} (n−jx). So the transfer equation should be :
f i + 1 , j + x , k + ( ⌊ l + x 2 ⌋ ∧ 1 ) , ⌊ l 2 ⌋ + x = ∑ f i , j , k , l × v i x × ( n − j x ) f_{i + 1, j + x, k + (\lfloor \frac {l + x}2 \rfloor \land 1), \lfloor\frac l2 \rfloor + x} = \sum f_{i, j, k, l} \times v_i^x \times \begin{pmatrix} n - j \\ x \end{pmatrix} fi+1,j+x,k+(⌊2l+x⌋∧1),⌊2l⌋+x=∑fi,j,k,l×vix×(n−jx)
Then we can preprocess the combination number and be happy d p dp dp La . The answer is :
a n s = ∑ i = 0 n ∑ j = 0 k [ j + p o p c n t ( i ) ≤ k ] f m , n , j , i ans = \sum_{i = 0}^n\sum_{j = 0}^k [j + popcnt(i) \leq k]f_{m, n, j, i} ans=i=0∑nj=0∑k[j+popcnt(i)≤k]fm,n,j,i
End of the flower !!!
Code
#include<bits/stdc++.h>
using namespace std;
#define in read()
#define MAXN 50
#define MAXM 505
#define MOD 998244353
inline int read(){
int x = 0; char c = getchar();
while(c < '0' or c > '9') c = getchar();
while('0' <= c and c <= '9'){
x = x * 10 + c - '0'; c = getchar();
}
return x;
}
int K = 0;
int n = 0; int m = 0;
int v[MAXM][MAXN] = {
0 }; // v[i][j] = v_i^j
int c[MAXN][MAXN] = {
0 };
int f[MAXM][MAXN][MAXN][MAXN] = {
0 };
int popcnt(int x){
int ans = 0;
while(x) ans += (x & 1), x >>= 1;
return ans;
}
int main(){
n = in; m = in; K = in; int ans = 0;
for(int i = 0; i <= m; i++){
v[i][0] = 1; v[i][1] = in;
for(int j = 2; j <= n; j++)
v[i][j] = 1ll * v[i][j - 1] * v[i][1] % MOD;
}
c[0][0] = 1;
for(int i = 1; i <= n; i++){
c[i][0] = 1;
for(int j = 1; j <= i; j++)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
}
f[0][0][0][0] = 1;
for(int i = 0; i <= m; i++)
for(int j = 0; j <= n; j++)
for(int k = 0; k <= K; k++)
for(int l = 0; l <= n >> 1; l++)
for(int x = 0; x <= n - j; x++)
f[i + 1][j + x][k + (l + x & 1)][l + x >> 1] = (f[i + 1][j + x][k + (l + x & 1)][l + x >> 1] + 1ll * f[i][j][k][l] * v[i][x] % MOD * c[n - j][x] % MOD) % MOD;
for(int j = 0; j <= K; j++)
for(int i = 0; i <= n >> 1; i++)
if(j + popcnt(i) <= K) ans = (ans + f[m + 1][n][j][i]) % MOD;
cout << ans << '\n';
return 0;
}
边栏推荐
- Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
- SQL Server 启停作业脚本
- [机缘参悟-51]:既然人注定要死亡,为什么还要活着?
- Data formatting widget
- XSS white list
- Network security - Web penetration testing
- Network security - filtering bypass injection
- Nmap安全测试工具使用教程
- Hcip day 13
- Kunyu(坤舆) 安装 详解
猜你喜欢

网络安全——文件上传竞争条件绕过

论文笔记:Swin-Unet: Unet-like Pure Transformer for MedicalImage Segmentation

Network security - use exchange SSRF vulnerabilities in combination with NTLM trunking for penetration testing

网络安全——Web渗透测试

Network security - file upload penetration test

CSP2021 T3 回文

Simple order management system small exercise

Swarm intelligence collaborative obstacle avoidance method inspired by brain attention mechanism

rhce第一次作业

Unity行人随机行走不碰撞
随机推荐
Packet switching and label switching in MPLS
Network security - file upload competitive conditions bypass
Flink综合案例(九)
网络安全——文件上传黑名单绕过
Network security - file upload content check bypass
Click event to create a new node
Interview question 01.02. determine whether it is character rearrangement
Data type binary string type
网络安全——文件上传内容检查绕过
How to install PHP 5.6 on Ubuntu 18.04 and Debian 9
Bayesian width learning system based on graph regularization
Explain flex layout in detail
Ansible服务常用命令模块详细解析
Flink fault tolerance mechanism (V)
Flink comprehensive case (IX)
Introduction to the separation of front and rear platforms of predecessors
关于不定方程解的个数的问题
How to verify the domain name after applying for SSL digital certificate?
R语言ggpubr包的ggarrange函数将多幅图像组合起来、annotate_figure为组合图像添加注释、注解、标注信息、使用left参数在可视化图像左侧添加注解信息(字体颜色、旋转角度等)
Network security - file upload whitelist bypass