Topic Link --SPOJ
topic Link - Los Valley
problem
Given n, m and a length of n number of columns c. Seeking a number of the number of columns of the following conditions are satisfied:
- \(1\le a_i < 2^m\)
- \(a_i\&a_{i-1}=0\)
- \(c_i\nmid a_i\)
Read the answer to \ (1000000000 \) modulo.
solution
With \ (F [t] [i] \) represents the length of t and the number i to satisfy the condition of the end of the sequence. \ (f [t] [i ] = \ sum \ limits_ {j, j \ & i = 0} f [t-1] [j] \)
Observation \ (j \ & i = 0 \) this limit, in fact, equivalent to \ (I \ & (\ SIM J) = I \) . So after each has been processed, the subscript answer with its own complement of exchange, then it becomes a superset of the enumeration. With \ (FMT \) optimization can be. Complexity \ (\ Theta (nm2 ^ m ) \)
Such processing over the first two limitations, for the third restriction, the subscript after each processed \ (C_i \) multiple answer becomes 0 can be.
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;
}