【题目链接】 http://www.spoj.com/problems/TLE/en/

【题目大意】

  给出n个数字c,求非负整数序列a,满足a<2^m
  并且有a[i]&a[i+1]=0,对于每个a[i],要保证a[i]不是c[i]的倍数,
  求这样的a[i]序列的个数

【题解】

  我们用dp[i]表示以i为结尾的方案数,
  我们发现要满足a[i]&a[i+1]=0,则dp[i]是从上一次结果中所有满足i&j=0的地方转移过来的
  i&j=0即i&(~j)=i,即i为~j的子集,那么我们每次对上一次的结果进行下标取反操作,
  那么求当前dp[i],就是求出以i为子集的上一次计算出的dp值的高维前缀和。
  对于c[i]这个条件,我们每轮计算后将c[i]倍数为下标的dp值置0即可。

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int T,n,m,c[100];
const int mod=1000000000;
struct data{
int val;
data operator +(const data &rhs)const{
int t_val=val+rhs.val;
if(t_val>=mod)t_val-=mod;
if(t_val<0)t_val+=mod;
return data{t_val};
}
}dp[(1<<15)+10],res;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&c[i]);
int all=1<<m;
for(int j=0;j<all;j++)dp[j].val=(j==0);
for(int i=1;i<=n;i++){
for(int j=0;j<all;j+=2)swap(dp[j],dp[j^(all-1)]);
for(int j=0;j<m;j++)for(int k=0;k<all;k++){
if(~k&(1<<j))dp[k]=dp[k]+dp[k|(1<<j)];
}for(int j=0;j<all;j+=c[i])dp[j].val=0;
}res.val=0;
for(int j=0;j<all;j++)res=res+dp[j];
printf("%d\n",res.val);
}return 0;
}

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

  1. SPOJTLE - Time Limit Exceeded(高维前缀和)

    题意 题目链接 题目的意思是给一个数组C,长度为n,每个数字的范围是2^m,然后要求构造一个数组a,满足 1.a[i] % C[i] !=0 ; 2.a[i] < 2^m ; 3.a[i] &a ...

  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. 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. YII 框架查询

    基础查询 Customer::find()->one();    此方法返回一条数据: Customer::find()->all();    此方法返回所有数据: Customer::f ...

  2. Java多线程学习(一)Java多线程入门

    转载请备注地址:https://blog.csdn.net/qq_34337272/article/details/79640870 系列文章传送门: Java多线程学习(一)Java多线程入门 Ja ...

  3. Composer 手动安装

    Linux/Mac 环境 sudo wget -O /usr/local/bin/composer https://dl.laravel-china.org/composer.phar sudo ch ...

  4. Java GC策略

    本文转自https://blog.csdn.net/rabbit_in_android/article/details/50386954 内存管理和垃圾回收 JVM内存组成结构 JVM栈由堆.栈.本地 ...

  5. xtraTabControl学习

    winform 首先是动态添加page面,并且在page页面上添加一个form窗体 DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraT ...

  6. Web开发中,页面渲染方案

    转载自:http://www.jianshu.com/p/d1d29e97f6b8 (在该文章中看到一段感兴趣的文字,转载过来) 在Web开发中,有两种主流的页面渲染方案: 服务器端渲染,通过页面渲染 ...

  7. hadoop3.1 ha高可用部署

    1.资源角色规划

  8. Two Sum ——经典的哈希表的题

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  9. CSAPP lab1 datalab-handout(深入了解计算机系统 实验一)

    主要涉及计算机中数的表示法: (1)整数: two's complement,即补码表示法 假设用N位bit表示整数w: 其中最左边一位为符号位,符号位为0,表示正数,为1表示负数. (2)浮点数: ...

  10. 配置文件中的mime-mapping元素(ofbiz/framework/catalina/config/mime-type)(

    mime-mapping元素将mime类型映射到扩展名. extension元素用来描述扩展名.mime-type元素则为MIME类型. <?xml version="1.0" ...