首页 > 其他分享 >状压DP

状压DP

时间:2024-03-28 18:25:17浏览次数:26  
标签:int 子集合 复杂度 状压 维度 DP

状压 就是把几个维度压成一个维度, 通常是按 \(k\) 进制来压缩

dp[(1 << 1145141919810)]

这样相当于开了 \(1145141919810\) 个只有 \(0/1\) 的维度, 二进制下每一位表示这个维度

运行逝世

查询一个集合 \(s\) 的所有子集合

扩散行

for(int i = s; i < MAXN; i = (i + 1) | s){
  // s 是 i 的子集合
}

扩散行

for(int i = s; i; i = (i - 1) & s){
  // i 是 s 的子集合
}

时间复杂度

如果一个数二进制下有 \(i\) 个 \(0\), 子集数为 \(2^i\)

如果是 \(n\) 个数, 时间复杂度 \(\sum \limits_{i = 0}^n C_{n}^{i} \cdot 2^i = O(3^n)\)

标签:int,子集合,复杂度,状压,维度,DP
From: https://www.cnblogs.com/liuyichen0401/p/18102336

相关文章

  • 设计模式DP-外观模式
    #include<stdio.h>#include<string.h>#include<stdlib.h>//定义子系统AtypedefstructsubsystemA{ void(*operationA)(structsubsystemA*subsystem);}SubsystemA;//定义子系统BtypedefstructsubsystemB{ void(*operationB)(structsubsystem......
  • 设计模式DP-责任链模式
    #include<stdio.h>#include<string.h>#include<stdlib.h>//定义业务处理者抽象类typedefstructHandler{ structHandler*nextHandler; void(*handleRequest)(structHandler*handler,intrequest); void(*setNextHandler)(structHandler*CurHan......
  • 设计模式DP-表驱动模式
    静态结构体数组式构建链表式构建链接式构建#include<stdio.h>#include<stdlib.h>#include<string.h> //加doublefun_add(doubledata_front,doubledata_back){ returndata_front+data_back;}//减doublefun_sub(doubledata_front,doubledata_back)......
  • 设计模式DP-模版模式
    #include<stdio.h>#include<string.h>#include<stdlib.h>typedefstructInterface_t{ /*初始化外设USB、SPI、IIC等*/ void(*init_peripheral)(void*obj); /*初始化硬盘*/ void(*init_disk)(void*obj); /*初始化内存*/ void(*init_memory)(void*obj);......
  • 设计模式DP-原型模式
    #include<stdio.h>#include<string.h>#include<stdlib.h>//定义抽象接口typedefstructinterface_t{ structinterface_t*(*clone)(void*obj); void(*set)(void*obj,constchar*name,intage); void(*show)(void*obj); charname[32];......
  • 一类适合记忆化搜索的区间dp
    https://www.luogu.com.cn/problem/P5752https://codeforces.com/contest/598/problem/Ecf这个题考虑dp预处理,状态是三维的,转移是分割方案和所分块需要获得的巧克力数量。最后题目多次询问可以o(1)快速查询的//Problem:E.ChocolateBar//Contest:Codeforces-Educational......
  • TCP与UDP:传输层协议对比
    ......
  • DDPG强化学习算法应用到TORCS仿真平台
    一、DDPG算法介绍1.前身DQN算法在介绍DDPG算法之前,需要首先明确它的前身DQN算法。DQN(DeepQ-Network)是一种用于强化学习的深度学习算法,由DeepMind公司开发。它结合了深度学习和Q-learning算法,旨在解决复杂环境下的强化学习问题。DQN算法在解决复杂环境下的强化学习问题方面取......
  • ThreadPool-线程池使用及原理
    1.线程池使用方式示例代码://一池N线程Executors.newFixedThreadPool(int)//一个任务一个任务执行,一池一线程Executors.newSingleThreadExecutorO//线程池根据需求创建线程,可扩容,遇强则强Executors.newCachedThreadPool()//自定义线程池方式newThreadPoolExec......
  • 动态规划刷题(算法竞赛、蓝桥杯)--数字三角形(线性DP)
    1、题目链接:[USACO1.5][IOI1994]数字三角形NumberTriangles-洛谷#include<bits/stdc++.h>usingnamespacestd;intr;constintN=1010;inta[N][N];intmain(){ cin>>r; for(inti=1;i<=r;i++){ for(intj=1;j<=i;j++){ cin>>a[i][j]; ......