SPOJ2829 TLE-Time Limit Exceeded
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的更多相关文章
- TLE - Time Limit Exceeded
TLE - Time Limit Exceeded no tags Given integers N (1 ≤ N ≤ 50) and M (1 ≤ M ≤ 15), compute the num ...
- SPOJ.TLE - Time Limit Exceeded(DP 高维前缀和)
题目链接 \(Description\) 给定长为\(n\)的数组\(c_i\)和\(m\),求长为\(n\)的序列\(a_i\)个数,满足:\(c_i\not\mid a_i,\quad a_i\& ...
- java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- Spark java.lang.outofmemoryerror gc overhead limit exceeded 与 spark OOM:java heap space 解决方法
引用自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246 ...
- Unable to execute dex: GC overhead limit exceeded
Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...
- [转]java.lang.OutOfMemoryError:GC overhead limit exceeded
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- android Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded
Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded 解决方法: 找到Eclipse安装目录的文件,\eclipse\e ...
- android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...
- GC overhead limit exceeded填坑心得
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- fix eclipse gc overhead limit exceeded in mac
fix eclipse gc overhead limit exceeded: 在mac上找不到eclipse.ini文件编辑内存限制,在eclipse安装目录右击eclipse程序,选“显示包内容” ...
随机推荐
- Kingfisher
Kingfisher ima1.kf.setImage(with: url) 为了兼容macOS, IOS 通过协议定义了kf,实际上就是本身 KingfisherOptionsInfo 可以配置一些 ...
- Virtual Box复制虚拟机
用惯了VM换BOX还是有点不大一样的,比如复制 我用了2个网卡,所以看起来麻烦了一次 注释了UUID 应该有更好的办法来操作,下面的看起来有点啰嗦,先凑合着这样弄... 1.关机 2.复制 3.改名称 ...
- js知识点面试题
网上看到的一个题,在这里存一下 此为题目function Foo() { getName = function () { alert (1); }; return this; } Foo.getNam ...
- qcom 8953平台 LCD亮灭屏流程及LCD知识点总结【转】
一.LK中亮屏流程 gcdb_display_init(),进行display初始化的起始地方: oem_panel_select(),在这里去选择哪一款屏,也可以在这里添加新一款屏: dsi_pan ...
- 【西北师大-2108Java】第十四次作业成绩汇总
[西北师大-2108Java]第十四次作业成绩汇总 作业题目 面向对象程序设计(JAVA) 第16周学习指导及要求 实验目的与要求 (1)掌握Java应用程序的打包操作: (2)掌握线程概念: (3) ...
- mysql数据库创建用户、赋权、修改用户密码
创建新用户 create user lisi identified by '123456'; 查看创建结果: 授权 命令格式:grant privilegesCode on dbName.tableN ...
- php 重复问题
结果: 结论: 尽量在方法内用变量去接受重复的参数或重复的方法/结果,消耗的时间积少成多
- Mysql的旧版本下载地址
直接进入:http://downloads.mysql.com/archives/community/
- TP5 where多条件查询
引用 : https://blog.csdn.net/haibo0668/article/details/78203170/
- 初识VEH链(用户异常派发的进一步探究)
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html 初识VEH链(用户异常派发的进一步探究) VEH链是进程处理异常 ...