题目链接

BZOJ3724

题解

构造矩阵的思路真的没想到

选\(x\)就不能选\(2x\)和\(3x\),会发现实际可以转化为矩阵相邻两项

\[\begin{matrix}1 & 3 & 9 & 27 & ... \\2 & 6 & 18 & 54 & ... \\4 & 12 & 36 & 108 & ... \\8 & 24 & 72 & 216 & ... \\ ... & ... &... &... &... \\ \end{matrix}
\]

相当于选这样的矩阵中不相邻的若干项的方案数

我们取每一个不是\(2\)和\(3\)的倍数的数作为矩阵左上角

行数和列数都很小,可以状压\(dp\)

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 20,maxm = (1 << 12),INF = 1000000000,P = 1000000001;
int f[maxn][maxm];
int N,n,cnt[maxn];
int ill[maxm],ans = 1;
void init(){
int t = 3;
for (int s = 0; s < maxm; s++){
for (int i = 0; i <= 10; i++)
if (((s & (t << i)) >> i) == t){
ill[s] = true; break;
}
}
}
void dp(int x){
for (n = 0; x <= N; x *= 2){
cnt[++n] = 0;
int t = x;
while (t <= N) cnt[n]++,t *= 3;
}
for (int i = 1; i <= n; i++)
for (int s = 0; s < (1 << cnt[i]); s++)
f[i][s] = 0;
for (int s = 0; s < (1 << cnt[1]); s++)
if (!ill[s]) f[1][s] = 1;
for (int i = 2; i <= n; i++)
for (int s = 0; s < (1 << cnt[i]); s++){
if (ill[s]) continue;
for (int e = 0; e < (1 << cnt[i - 1]); e++){
if (ill[e]) continue;
if (!(s & e)){
f[i][s] = (f[i][s] + f[i - 1][e]) % P;
}
}
}
int re = 0;
for (int s = 0; s < (1 << cnt[n]); s++)
re = (re + f[n][s]) % P;
ans = 1ll * ans * re % P;
}
int main(){
init();
scanf("%d",&N);
for (int i = 1; i <= N; i++){
if (i % 2 == 0 || i % 3 == 0) continue;
dp(i);
}
printf("%d\n",ans);
return 0;
}

BZOJ3724 [HNOI2012]集合选数 【状压dp】的更多相关文章

  1. [HNOI2012]集合选数 --- 状压DP

    [HNOI2012]集合选数 题目描述 <集合论与图论>这门课程有一道作业题,要求同学们求出\({1,2,3,4,5}\)的所有满足以 下条件的子集:若 x 在该子集中,则 2x 和 3x ...

  2. bzoj 2734: [HNOI2012]集合选数 状压DP

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 321[Submit][Status ...

  3. BZOJ 2734 [HNOI2012]集合选数 (状压DP、时间复杂度分析)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2734 题解 嗯早就想写的题,昨天因为某些不可告人的原因(大雾)把这题写了,今天再来写题解 ...

  4. 洛谷$P3226\ [HNOI2012]$集合选数 状压$dp$

    正解:$dp$ 解题报告: 传送门$QwQ$ 考虑列一个横坐标为比值为2的等比数列,纵坐标为比值为3的等比数列的表格.发现每个数要选就等价于它的上下左右不能选. 于是就是个状压$dp$板子了$QwQ$ ...

  5. $HNOI2012\ $ 集合选数 状压$dp$

    \(Des\) 求对于正整数\(n\leq 1e5\),{\(1,2,3,...,n\)}的满足约束条件:"若\(x\)在该子集中,则\(2x\)和\(3x\)不在该子集中."的子 ...

  6. bzoj 2734 [HNOI2012]集合选数 状压DP+预处理

    这道题很神啊…… 神爆了…… 思路大家应该看别的博客已经知道了,但大部分用的插头DP.我加了预处理,没用插头DP,一行一行来,速度还挺快. #include <cstdio> #inclu ...

  7. 【BZOJ-2732】集合选数 状压DP (思路题)

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1070  Solved: 623[Submit][Statu ...

  8. 【BZOJ-2734】集合选数 状压DP (思路题)

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1070  Solved: 623[Submit][Statu ...

  9. BZOJ_2734_[HNOI2012]集合选数_构造+状压DP

    BZOJ_2734_[HNOI2012]集合选数_构造+状压DP 题意:<集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x ...

随机推荐

  1. python的rtree包缺失libspatiaindex.so

    1 准备autoconf工具 yum -y install autoconf automake libtool 2 准备g++编译器 yum -y install gcc gcc-c++ 3 下载并安 ...

  2. 在tomcat5中发布项目时,用IP地址+端口不能访问项目,而用localhost加端口时可以访问成功

    最近在开发项目中,遇到的一个问题是: 在 tomcat中发布一个web项目,但是发布成功后,只能用http://localhost:8080/fm访问项目,不能用 http://127.0.0.1:8 ...

  3. Jmeter接口测试(四)传递参数

    参数设置 Jmeter 支持通过 查询字符串参数(Query String Parameters) 或者 Request body 请求体来传递参数. 1.get请求是普通键值对 get请求一般通过p ...

  4. Appium+python HTML测试报告(2)——一份报告模板(转)

    (原文:https://www.cnblogs.com/fancy0158/p/10055003.html) 适用于python3: 下载地址: 英文:https://pan.baidu.com/s/ ...

  5. git拉代码,IntelliJ idea报错,cannot load module xxxxx

    1 从git上下工程的时候,IntelliJ idea报错,cannot load module xxxx VCS-git-clone-ssh:xxxx ,报错cannot load module x ...

  6. 配置文件语言之yaml

    一. Yaml YAML 是一种简洁的非标记语言.YAML以数据为中心,使用空白,缩进,分行组织数据,从而使得表示更加简洁易读. 由于实现简单,解析成本很低,YAML特别适合在脚本语言中使用.列一下现 ...

  7. [二读]The Art of Pompeii's Influence on Neo-Classicism

    The Art of Pompeii's Influence on Neo-Classicism The discovery of Pompeii's ruins in 1599 profoundly ...

  8. 422. Length of Last Word【LintCode java】

    Description Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ...

  9. mui搜索框 搜索点击事件

    <div class="mui-input-row mui-search"> <input type="search" class=" ...

  10. 探路者 Alpha阶段中间产物

     版本控制 git地址:https://git.coding.net/clairewyd/toReadSnake.git   贪吃蛇(单词版)软件功能说明书 1 开发背景 “贪吃蛇”这个游戏对于80, ...