题目链接

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. iOS 关于权限设置的问题

      在info.plist文件下添加 <key>NSContactsUsageDescription</key>    <string>请求访问通讯录</st ...

  2. php oci8 小试

    Oracle_db.class.php <?phpclass Oracle_db{    public $link;    public function __construct(){      ...

  3. Nginx特性验证-反向代理/负载均衡/页面缓存/URL重定向

    原文发表于cu:2016-08-25 参考文档: Nginx 反向代理.负载均衡.页面缓存.URL重写等:http://freeloda.blog.51cto.com/2033581/1288553 ...

  4. PHP性能优化 -实战篇

    借助xhprof 工具分析PHP性能 XHPorf(源自Fackbook 的PHP性能分析工具) 实战     通过分析Wordpress程序,做优化! 优化 找到需要优化的函数 grep 'impo ...

  5. Tree - Gradient Boosting Machine with sklearn source code

    This is the second post in Boosting algorithm. In the previous post, we go through the earliest Boos ...

  6. 苹果没放弃手写笔 这样的iPad你想要吗?

    12 月 31 日,美国专利与商标局(The U.S. Patent and Trademark Office)当地时间周四批准了一项来自苹果的专利申请,该专利主要描述的是一种可以通过陀螺仪.无线通讯 ...

  7. Spark入门(Python)

    Hadoop是对大数据集进行分布式计算的标准工具,这也是为什么当你穿过机场时能看到”大数据(Big Data)”广告的原因.它已经成为大数据的操作系统,提供了包括工具和技巧在内的丰富生态系统,允许使用 ...

  8. Alpha发布——视频博客

    1.视频链接 视频上传至优酷自频道,地址链接:https://v.youku.com/v_show/id_XMzg5MzQ4MzM2MA==.html?spm=a2h0k.11417342.sores ...

  9. oracle数据库 expdp/impdp 和 exp/imp

    --EXPDP导出,需要系统用户权限,一般不使用--sqlplus--1.创建dmp导出逻辑目录 create directory 目录名 as '目录路径' create directory exp ...

  10. Java变量声明,实例化,问题

    1.变量在输出前必须实例化,这是因为只有声明,没有分配内存空间 在这种情况下会报错 2.实例化后,尽管没有赋值,可能是默认了吧,但也不会输出null,什么也没有输出 上面的理解可能是错的,a赋值了,就 ...