TLE - Time Limit Exceeded
TLE - Time Limit Exceeded
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的更多相关文章
- 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程序,选“显示包内容” ...
随机推荐
- JSP页面规格化
http://doc.okbase.net/%E4%BA%BA%E7%94%9F%E9%9A%BE%E5%BE%97%E7%B3%8A%E6%B6%82/archive/123084.html htt ...
- 特征变化--->索引到标签的转换(IndexToString)
package Spark_MLlib import org.apache.spark.ml.feature.{IndexToString, StringIndexer} import org.apa ...
- jsp简单学习总结
以下均为jsp页面 1:<jsp:include page="index.jsp"/>相当于嵌入一个页面.还有一种是<frame src="main_l ...
- [Swift通天遁地]四、网络和线程-(12)使用ReachabilitySwift实现对网络状态的检测
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- windows下 redis/tomcat 服务自启动
//设置redis服务自启动 //根据个人配置执行语句. redis-server --service-install redis.windows.conf --loglevel verbose ...
- 自己做的一个android 音视频播放器
欢迎大家下载: http://download.csdn.net/detail/q610098308/8504335
- 涨知识---V
1.内存对齐 在解释内存对齐的作用前,先来看下内存对齐的规则: 1). 对于结构的各个成员,第一个成员位于偏移为0的位置,以后每个数据成员的偏移量必须是min(#pragma pack()指定的数, ...
- 下载谷歌地图封锁IP解决办法
采用重新拨号,动态改变IP的方式.可以使用软件<易好用IP自动更换软件>
- UE4 集成讯飞听写插件
搞了几天,有些坑记录一下. 3个方面的知识需要学习 1.制作UE4插件 2.引入第三方库 3.讯飞听写的api 一看是参考 https://blog.csdn.net/u012793104/artic ...
- synchronized关键字详解(二)
synchronized关键字的性质 1.可重入:同一线程的外层函数获得锁之后,内层函数可直接再次获得该锁,好处:避免死锁,提升封装性 证明可重入粒度:1.同一个方法是可重入的 2.可重入不要求是同一 ...