当前位置:网站首页>[Luogu p3220] and not (construction) (digit DP) (inference)
[Luogu p3220] and not (construction) (digit DP) (inference)
2022-07-19 14:27:00 【SSL_ TJH】
And non
Topic link :luogu P3220
The main idea of the topic
Give you an operation called and not , Is to add up two numbers and take the opposite .
Then I'll give you some K Bit binary number , Ask how much you can get through operation in L~R The number in .
Ideas
A very interesting question !
You consider this operation : n o t ( A & B ) not(A\& B) not(A&B)
Yourself and yourself : n o t ( A & A ) = n o t ( A ) not(A\&A)=not(A) not(A&A)=not(A), Non operational
After the operation, it's not about : n o t ( n o t ( A & A ) ) = A & A not(not(A\&A))=A\&A not(not(A&A))=A&A, And operation .
That or operation also has : n o t ( n o t ( A ) & n o t ( B ) ) not(not(A)\¬(B)) not(not(A)¬(B))
That XOR also has :( Just one true and one false ) ( A & n o t ( B ) ) o r ( n o t ( A ) & B ) (A\& not(B))or(not(A)\&B) (A¬(B))or(not(A)&B)
Then these four operations are available. It seems that everything can be done , Then consider looking for exceptions .
You will find that if for all the numbers given , There is either between two people 1 1 1 Or both. 0 0 0, You can't come up with 10 , 01 10,01 10,01 These , So this is equivalent to forming several connected blocks .
Then we can digital DP Did .
Then let's consider why this is not enough , That is why the rest of the situation can .
( Let's treat these bindings as a )
We consider having XOR , Let's use the idea similar to linear basis , Consider finding out that only one is 1 1 1 The situation of .
In this way, you can or get all .
How do you get a position ? Let's consider no matter where else , We just need a place 1 1 1.
Then we can count all the numbers , This one is 1 1 1 Yes, it works normally , If it's not, it's reversed and reused , In this way, all you get together , This one is 1 1 1, And it seems that everything else will be 0 0 0.
When you think about it carefully, you will find that it is indeed like this , Because if the other one is 1 1 1, Who is this one 1 1 1 Where it is 1 1 1, yes 0 0 0 It also if 0 0 0, That's exactly the same , Can binding be regarded as one ?
So it proves .
Code
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const ll N = 1005;
ll n, K, lim[60];
bool sam[60][60], sp[60];
ll L, R, a[N];
ll clac(ll R, ll wei, bool ding) {
if (wei < 0) return 1;
if (!ding) {
ll num = 0; for (ll i = 0; i <= wei; i++) if (sp[i]) num++;
return (1ll << num);
}
if (lim[wei] == -1) {
ll re = 0;
for (ll i = 0; i <= ((R >> wei) & 1); i++) {
ll tmp = 0;
for (ll j = 0; j < wei; j++) if (sam[wei][j]) lim[j] = i;
re += clac(R, wei - 1, i == ((R >> wei) & 1));
for (ll j = 0; j < wei; j++) if (sam[wei][j]) lim[j] = -1;
}
return re;
}
else {
if (lim[wei] == 1 && !((R >> wei) & 1)) return 0;
return clac(R, wei - 1, lim[wei] == ((R >> wei) & 1));
}
}
ll work(ll R) {
memset(lim, -1, sizeof(lim));
if (R < 0) return 0;
return clac(R, K - 1, (R >> K) ? 0 : 1);
}
int main() {
scanf("%lld %lld %lld %lld", &n, &K, &L, &R);
for (ll i = 0; i < K; i++) for (ll j = 0; j < K; j++) sam[i][j] = 1;
for (ll i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
for (ll k = 0; k < K; k++)
for (ll kk = 0; kk < k; kk++)
if (((a[i] >> k) & 1) ^ ((a[i] >> kk) & 1)) sam[k][kk] = sam[kk][k] = 0;
}
for (ll i = 0; i < K; i++) {
sp[i] = 1;
for (ll j = i + 1; j < K; j++) if (sam[i][j]) {
sp[i] = 0; break;}
}
printf("%lld", work(R) - work(L - 1));
return 0;
}
边栏推荐
- 毕设-基于SSM在线预约挂号系统
- 面额10exp(303)的钞票
- ClassNotFoundException:com.tongweb.geronimo.osgi.locator.ProviderLocator
- Redis source code and design analysis -- 4 Jump table
- Prefix Equality 【DP | 哈希】
- Si446 usage record (III): match function
- Luo Gu: p3092 [usaco13nov]no change G
- Is it safe for Hongye futures to open an account online? Are there any account opening guidelines?
- Robotics at Google:Laura Graesser | i-Sim2Real:在紧密的人机交互循环中强化学习机器人策略
- Redis源码与设计剖析 -- 4.跳跃表
猜你喜欢

Ranking of top ten ERP software systems at home and abroad!

Addition, deletion, modification and query of database

BiShe - online reservation and registration system based on SSM

matplotlib绘制多折线图(解决matplotlib中文无法显示问题)

CMAKE学习笔记

A review of classical must see for Nonconvex Optimization Problems "from symmetry to geometry", University of Rochester, et al

The NFT market pattern has not changed. Can okaleido set off a new round of waves?

Use tongweb's hot deployment function with caution

JVM performance optimization

Win10 Microsoft Store cannot be opened (enable TLS 1.2)
随机推荐
Huawei wireless device configuration dynamic load balancing
【luogu P3220】与非(构造)(数位DP)(推论)
同一宿主机不同容器网络通信流程分析
Redis source code and design analysis -- 2 Linked list
C. Watto and Mechanism(哈希 | 字典树 + dfs (树上dfs))
JVM性能优化
华为无线设备配置用户CAC
Optimal biking strategy [DP + two points]
The manual is not complete. How to manually dig out the monitoring information of tongweb?
Minuterie logicielle à puce unique v2.0
009 execution sequence of SQL statement of interview questions
js刷题练习---牛客网
Manuel incomplet, comment tracer manuellement l'information de surveillance de tongweb?
CMAKE学习笔记
Tongweb production system emergency treatment plan
敏捷的第一步:把 “迭代” 变为 “冲刺” 开始!
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
手册不全,如何手工刨出TongWeb的监控信息?
[acwing] solution of the 60th weekly match
欧奈尔的RPS曲线的编制方法(陶博士原创)