题目传送门

题目大意

直接看题面吧。

思路

感觉挺水的一道题啊?怎么评到紫色的啊?考试的时候LJS出了这个题的加强版我就只想出这个思路,然后就爆了。。。

不难发现,我们可以构造矩阵:

x 2x 4x 6x ...
3x 6x 12x 24x 48x ...
9x 18x 36x ...

然后实际上就相当于在这个矩阵中选出一些数使得两两不相邻。因为行数列数都是 \(\log\) 级别的,所以直接状压就好了。

\(\texttt{Code}\)

#include <bits/stdc++.h>
using namespace std; #define Int register int
#define mod 1000000001
#define MAXN 1000005 template <typename T> void read (T &x){char c = getchar ();x = 0;int f = 1;while (c < '0' || c > '9') f = (c == '-' ? -1 : 1),c = getchar ();while (c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar ();x *= f;}
template <typename T,typename ... Args> void read (T &x,Args& ... args){read (x),read (args...);}
template <typename T> void write (T x){if (x < 0) x = -x,putchar ('-');if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> void Mx (T &a,T b){a = max (a,b);}
template <typename T> void Mi (T &a,T b){a = min (a,b);} bool mark[MAXN];
int n,a[25][25],lim[25]; void init (int x){
a[1][1] = x;
for (Int i = 1;i <= 15;++ i){
if (i > 1) a[i][1] = a[i - 1][1] * 3;
if (a[i][1] > n) break;
for (Int j = 2;j <= 20;++ j){
a[i][j] = a[i][j - 1] * 2;
if (a[i][j] > n){
lim[i] = j - 1;
break;
}
}
for (Int j = 1;j <= lim[i];++ j) mark[a[i][j]] = 1;
}
} bool chk[1 << 21];
int dp[2][1 << 22]; int WorkDP (){
int endl = 0;
for (Int i = 0;i < (1 << lim[1]);++ i) dp[1][i] = chk[i];
for (Int i = 2;i <= 15;++ i){
if (a[i][1] > n){
endl = i - 1;
break;
}
for (Int S = 0;S < (1 << lim[i]);++ S) if (chk[S]){
dp[i & 1][S] = 0;
for (Int S1 = 0;S1 < (1 << lim[i - 1]);++ S1)
if ((S & S1) == 0) dp[i & 1][S] += dp[i - 1 & 1][S1],dp[i & 1][S] %= mod;
}
else dp[i & 1][S] = 0;
}
int ans = 0;
for (Int S = 0;S < (1 << lim[endl]);++ S) ans += dp[endl & 1][S],ans %= mod;
return ans;
} signed main(){
read (n);int res = 1;
for (Int i = 0;i < (1 << 20);++ i) chk[i] = ((i & (i >> 1)) == 0);
for (Int i = 1;i <= n;++ i) if (!mark[i]) init (i),res = 1ll * res * WorkDP () % mod;
write (res),putchar ('\n');
return 0;
}

最新文章

  1. Step by Step 创建一个新的Dynamics CRM Organization
  2. Linux学习 :字符设备框架
  3. PHP取整函数:ceil,floor,round,intval的区别详细解析
  4. game of life
  5. Linux批量修改用户密码
  6. Android编码风格
  7. win8.1 cygwin编译java轻量虚拟机avian
  8. Ehcache详细解读(转载)
  9. OpenJudge/Poj 1207 The 3n + 1 problem
  10. MySQL 授权详解
  11. struts2中的&lt;s:select&gt;默认选项
  12. Codeforces446C - DZY Loves Fibonacci Numbers
  13. Mesos+Zookeeper+Marathon的Docker管理平台部署记录(2)- 负载均衡marathon-lb
  14. 网络编程socketserver实现并发
  15. IO练习文件读取
  16. RMAN常用命令汇总!
  17. DNS的服务器和客户端的配置
  18. BeagleBone Black教程之BeagleBone Black使用到的Linux基础
  19. 【Unity】角色沿路线移动/朝着目标移动
  20. SQL脚本去重分组统计

热门文章

  1. centos7 netstat
  2. D3之svg transform 与 css3 transform 区别与联系
  3. sublime text 的 Ctrl + P「模糊搜索算法」
  4. Linux 安装 Harbor 私有镜像仓库
  5. SQLServer数据实时同步PostgreSQL
  6. 一个Django项目中实现的简单HTML页面布局
  7. noip模拟45
  8. 以人为本打造“超职季”IP,58同城精准匹配企业招聘与打工人
  9. [第二篇]——Docker 架构之Spring Cloud直播商城 b2b2c电子商务技术总结
  10. freeswitch 编译安装后的配置