题目链接——SPOJ

题目链接——洛谷

problem

给出n,m和一个长度为n的数列c。求有多少个数列a满足以下条件:

  • \(1\le a_i < 2^m\)
  • \(a_i\&a_{i-1}=0\)
  • \(c_i\nmid a_i\)

答案读对\(1000000000\)取模。

solution

用\(f[t][i]\)表示长度为t且以i结尾的满足条件的数列的数量。\(f[t][i]=\sum\limits_{j,j\&i=0}f[t-1][j]\)

观察\(j\&i=0\)这个限制,其实等价于\(i\&(\sim j)=i\)。所以每次处理完之后,将答案的下标与自己的补集交换,然后就成了枚举超集。用\(FMT\)优化即可。复杂度\(\Theta(nm2^m)\)

这样处理完了前两个限制,对于第三个限制,每次处理完之后将下标\(c_i\)倍数的答案变为0即可。

code

/*
* @Author: wxyww
* @Date: 2019-12-15 09:58:26
* @Last Modified time: 2019-12-15 10:11:19
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 1 << 20,mod = 1000000000;
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar();
}
return x * f;
}
int f[N],a[N];
int main() {
int T = read();
while(T--) {
int n = read(),m = read();
int LIM = (1 << m) - 1;
memset(f,0,sizeof(f));
f[0] = 1;
for(int i = 1;i <= n;++i) a[i] = read(); for(int i = 1;i <= n;++i) { for(int j = 0;j <= LIM;j += 2) swap(f[j],f[j ^ LIM]); for(int j = 0;j < m;++j) {
for(int k = 0;k <= LIM;++k) {
if(!(k >> j & 1)) f[k] += f[k | (1 << j)],f[k] %= mod;
}
}
for(int j = 0;j <= LIM;j += a[i]) f[j] = 0;
} ll ans = 0;
for(int i = 0;i <= LIM;++i) ans += f[i],ans %= mod; printf("%lld\n",ans); } return 0;
}

SPOJ2829 TLE-Time Limit Exceeded的更多相关文章

  1. TLE - Time Limit Exceeded

    TLE - Time Limit Exceeded no tags  Given integers N (1 ≤ N ≤ 50) and M (1 ≤ M ≤ 15), compute the num ...

  2. SPOJ.TLE - Time Limit Exceeded(DP 高维前缀和)

    题目链接 \(Description\) 给定长为\(n\)的数组\(c_i\)和\(m\),求长为\(n\)的序列\(a_i\)个数,满足:\(c_i\not\mid a_i,\quad a_i\& ...

  3. java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  4. Spark java.lang.outofmemoryerror gc overhead limit exceeded 与 spark OOM:java heap space 解决方法

    引用自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246 ...

  5. Unable to execute dex: GC overhead limit exceeded

    Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...

  6. [转]java.lang.OutOfMemoryError:GC overhead limit exceeded

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  7. android Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded

    Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded 解决方法: 找到Eclipse安装目录的文件,\eclipse\e ...

  8. android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded

    android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...

  9. GC overhead limit exceeded填坑心得

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  10. fix eclipse gc overhead limit exceeded in mac

    fix eclipse gc overhead limit exceeded: 在mac上找不到eclipse.ini文件编辑内存限制,在eclipse安装目录右击eclipse程序,选“显示包内容” ...

随机推荐

  1. Python3如何安装pip工具?

    前几天安装Python的时候没有装上pip工具,所以只能现在手动安装了. 首先,访问https://bootstrap.pypa.io/get-pip.py这个网址,然后Ctrl+S将get-pip. ...

  2. 【js】canvas——Atomic-particle-motion

    原子粒动 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  3. [转]UiPath Keyboard Shortcuts

    本文转自:https://docs.uipath.com/studio/docs/keyboard-shortcuts The complete list of keyboard shortcuts ...

  4. synchronized凭什么锁得住?

    相关链接: <synchronized锁住的是谁?> 我们知道synchronized是重量级锁,我们知道synchronized锁住的是一个对象上的Monitor对象,我们也知道sync ...

  5. RSA加解密&RSA加验签详解

    RSA 加密算法是目前最有影响力的 公钥加密算法,并且被普遍认为是目前 最优秀的公钥方案 之一.RSA 是第一个能同时用于 加密 和 数字签名 的算法,它能够 抵抗 到目前为止已知的 所有密码攻击,已 ...

  6. ORDER BY导致索引使用不理想

    在MySQL中经常出现未按照理想情况使用索引的情况,今天记录一种Order by语句的使用导致未按预期使用索引的情况. 1.  问题现象 1.1 SQL语句: SELECT DISTINCT p.* ...

  7. Win10锁屏壁纸位置

    C:\Users\MIS\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalStat ...

  8. 数据结构导论 四 线性表的顺序存储VS链式存储

    前几章已经介绍到了顺序存储.链式存储 顺序存储:初始化.插入.删除.定位 链式存储:初始化.插入.删除.定位 顺序存储:初始化 strudt student{ int ID://ID char nam ...

  9. 6 Ubuntu软件安装

      6 软件安装¶ 6.1 通过apt 安装/卸载软件¶ apt是Advanced Packaging Tool,是Linux下的一款安装包管理工具 可以在终端中方便的安装/卸载/更新软件包 # 1. ...

  10. win 10 命令行导出注册表

    命令如下: reg  export  注册表中的key  保存路径 reg export HKLM\Software\MyCo\MyApp AppBkUp.reg 如果需要直接覆盖原来的文件,可以加上 ...