TLE - Time Limit Exceeded

no tags 

Given integers N (1 ≤ N ≤ 50) and M (1 ≤ M ≤ 15), compute the number of sequences a1, ..., aN such that:

  • 0 ≤ ai < 2M
  • ai is not divisible by ci (0 < ci ≤ 2M)
  • ai & ai+1 = 0 (that is, ai and ai+1 have no common bits in their binary representation)

Input

The first line contains the number of test cases, T (1 ≤ T ≤ 10). For each test case, the first line contains the integers N and M, and the second line contains the integers c1, ..., cN.

Output

For each test case, output a single integer: the number of sequences described above, modulo 1,000,000,000.

Example

Input:
1
2 2
3 2 Output:
1

The only possible sequence is 2, 1.

分析:考虑相邻a[i]&a[i+1]=0;

   初始化状态转移为dp[i][j]=dp[i-1][j^((1<<m)-1)];

   dp[i][j]表示第i步为j的方案数;

   其次,若j&k=j,则dp[i][j]也应包含dp[i][k],这个可以推回去与一下;

   dp[i][j]=Σdp[i][k],j&k=j,这个即为高维前缀和;

   剩下不被整除特判一下即可;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000000
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+;
const int N=2e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[],dp[][<<];
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&m);
rep(i,,n)scanf("%d",&a[i]);
rep(i,,(<<m)-)if(i%a[]!=)dp[][i]++;
rep(i,,n)
{
rep(j,,(<<m)-)dp[i][j]=dp[i-][j^((<<m)-)];
rep(j,,m-)
{
rep(k,,(<<m)-)
{
if((~k)&(<<j))(dp[i][k]+=dp[i][k^(<<j)])%=mod;
}
}
for(j=;j<(<<m);j+=a[i])dp[i][j]=;
}
ll ret=;
rep(i,,(<<m)-)(ret+=dp[n][i])%=mod;
printf("%lld\n",ret);
}
return ;
}

TLE - 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. java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得

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

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

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

  4. Unable to execute dex: GC overhead limit exceeded

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

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

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

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

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

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

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

  8. GC overhead limit exceeded填坑心得

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

  9. fix eclipse gc overhead limit exceeded in mac

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

随机推荐

  1. [HNOI2006]潘多拉的宝盒

    https://www.zybuluo.com/ysner/note/1250303 题面 给定\(s\)个自动机,如果某个自动机\(A\)能产生的所有串都能在自动机\(B\)中产生(即走相同\(0/ ...

  2. IDEA Spark Streaming 操作(套接字流)-----make socket数据源

    import java.io.PrintWriter import java.net.ServerSocket import scala.io.Source object DStream_makeSo ...

  3. CSS小代码汇总整理

    /**实现斑马线的表格*/table.flexme tbody tr:nth-child(2n){background-color:#D6E7FC;} /*返回偶数序的子元素*/table.flexm ...

  4. codevs 2541 幂运算(迭代加深搜索)

    2541 幂运算  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description 从m开始,我们只需要6次运算就可以计算出m31 ...

  5. codevs1486愚蠢的矿工(树形dp)

    1486 愚蠢的矿工  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description Stupid 家族得知在HYC家的后花园里的中央花坛处,向北走3步,向西走3步, ...

  6. [Apple开发者帐户帮助]九、参考(6)支持的功能(watchOS)

    watchOS扩展可用的功能取决于您的程序成员身份. 注意:对于watchOS应用程序目标,可用的功能是应用程序组和后台模式,并且不依赖于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用 ...

  7. MFC学习篇(一):用OpenCV显示视频

    首先是一些基础的步骤,如建立MFC应用,添加按钮等,博主主要参考了下面这篇文章,其中的前32步都是用OpenCV显示图片和视频所必须的,即通用的.由于LZ原来有配置OpenCV的基础,所以配制还是比较 ...

  8. 为什么选择Android Studio 而是 Eclipse

    Android Studio 现在的版本已经比较稳定了,刚出来时也是各种BUG,自己用了下,摸索了一天,感觉挺好的. 优点之一:代码提示和搜索功能非常强大,非常智能. 1).自定义theme有个名字叫 ...

  9. Unity学习-预制(四)

    预制即克隆 比如要模拟一个下雨的场景,天下掉下来一颗一颗的雨滴.如果此时,我们给每一个雨滴创建一个对象的话,那会很浪费资源,而且也没必要,因为所有的雨滴是相同的.这个时候就使用到了预制,一种可以被重复 ...

  10. 如何下载Nginx(Windows) 并且简单使用

    官网地址:http://nginx.org/ 进入官网后点击: 推荐下载的是稳定版: 现在开始简单的使用: 一.打开下载文件的目录解压后打开文件 二.在其他盘新建一个test.html,静态资源,用来 ...