题意

题目链接

题目的意思是给一个数组C,长度为n,每个数字的范围是2^m,然后要求构造一个数组a,满足

1、a[i] % C[i] !=0 ;

2、a[i] < 2^m ;

3、a[i] & a[i+1] = 0;

Sol

直接dp的话就是先枚举补集的子集,这样的复杂度是\(3^n\)的

然后补集的子集可以用高位前缀和优化一下

时间复杂度:\(O(2^n * n)\)

#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1e5 + 10, mod = 1000000000;
inline int read() {
char c = getchar(); int x = 0, f = 1;
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 N, M, a[MAXN], c[MAXN], f[51][65537], sum[51][65537];
int add(int &x, int y) {
x = (x + y >= mod ? x + y - mod : x + y);
}
int solve() {
N = read(); M = read(); int Lim = (1 << M) - 1;
memset(f, 0, sizeof(f));
memset(sum, 0, sizeof(sum));
f[0][0] = 1;
for(int i = 0; i <= Lim; i++) sum[0][i] = 1;
for(int i = 1; i <= N; i++) {
c[i] = read();
for(int sta = 1; sta <= Lim; sta ++) {
if(!(sta % c[i])) continue;
int s = (~sta) & Lim;
sum[i][sta] = f[i][sta] = sum[i - 1][s];
}
for(int j = 0; j < M; j++)//必须先枚举这个
for(int sta = 0; sta <= Lim; sta++)
if(sta & (1 << j)) add(sum[i][sta], sum[i][sta ^ (1 << j)]);
}
int ans = 0;
for(int i = 0; i <= Lim; i++) add(ans, f[N][i]);
return ans;
}
int main() {
int T = read();
while(T--) printf("%d\n", solve());
return 0;
}

SPOJTLE - Time Limit Exceeded(高维前缀和)的更多相关文章

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

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

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

    [题目链接] http://www.spoj.com/problems/TLE/en/ [题目大意] 给出n个数字c,求非负整数序列a,满足a<2^m 并且有a[i]&a[i+1]=0, ...

  3. TLE - Time Limit Exceeded

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

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

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

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

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

  6. Unable to execute dex: GC overhead limit exceeded

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

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

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

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

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

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

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

随机推荐

  1. jenkins checkstyle:local variable hides a field

    源代码: 1 2 3 4 5 6 7 8 //应用上下文 private static ApplicationContext applicationContext; public static voi ...

  2. nagios系列(七)nagios通过自定义脚本的方式监控mysql主从同步

    nagios监控mysql主从同步 起因:nagios可能监控到mysql服务的运行情况,但确不能监控mysql的主从复制是否正常:有时候,同步已经停止,但管理人员却不知道. 登陆mysql从服务器, ...

  3. SKlearn库学习曲线

    思想: # 1.现将所有样本用交叉验证方法或者(随机抽样方法) 得到 K对 训练集-验证集# 2.依次对K个训练集,拿出数量不断增加的子集如m个,并在这些K*m个子集上训练模型.# 3.依次在对应训练 ...

  4. SQL代码整理

    --SQL代码整理: create database mingzi--创建数据库go--连接符(可省略)create table biao--创建表( lieming1 int not null,-- ...

  5. 学习笔记(二)--->《Java 8编程官方参考教程(第9版).pdf》:第七章到九章学习笔记

    注:本文声明事项. 本博文整理者:刘军 本博文出自于: <Java8 编程官方参考教程>一书 声明:1:转载请标注出处.本文不得作为商业活动.若有违本之,则本人不负法律责任.违法者自负一切 ...

  6. tomcat 输入学习

    Tomcat学习—Tomcat7 修改/webapps/ROOT发布路径(Linux和windows环境) https://blog.csdn.net/u010648555/article/detai ...

  7. python接口自动化测试二十七:加密与解密MD5、base64

    # MD5加密 # 由于MD5模块在python3中被移除# 在python3中使用hashlib模块进行md5操作 import hashlib def MD5(str): # 创建md5对象 hl ...

  8. python+selenium+unittest 实现自动化测试

    示例代码: baidu.py import csv #导入csv模块 from itertools import islice #从itertools导入islice,后边让其默认跳过第一行使用 fr ...

  9. ubuntu下java8卸载

    要删除 OpenJDK (如果已安装的话).首先,检查是安装的哪个 OpenJDK包. # dpkg --list | grep -i jdk 移除 openjdk包: # apt-get purge ...

  10. #10 [AH2017/HNOI2017]大佬

    题解: 题意看上去挺复杂的 分析一下就能发现自己的自信是没啥用的 只要随便dp一下看看最多能有多少天不使用增加自信 然后问题就变成了 求C1+C2+k=C 然后发现C有10^8 显然枚举C1是不行的了 ...