CF238A Not Wool Sequences

Solution

看到是一个异或和的序列,我们可以考异或的性质。

我们构造一个数组 \(b\)\(b_0=0,b_i=a_i\oplus b_{i-1}\) ,由异或性质得 \(a_i=b_i\oplus b_{i-1}\) ,所以 \(a_l\oplus a_{l+1}\oplus\cdots\oplus a_r\not=0\Rightarrow b_{l-1}\oplus b_r\not= 0\) ,题目中说 \(l\leq r\) ,所以 \(b\) 数组中的每个数都不相同。

因为 \(a_i=b_i\oplus b_{i-1}\) ,所以 \(b_i\in[1,2^m]\) ,则答案就是找长度为 \(n\) 的数组且数组中的数在 \([1,2^m]\) 各不相同,即 \(A_{2^m}^n\)

代码

#include<bits/stdc++.h>
#define ll long long

using namespace std;
const int mod=1e9+9;
int n,m; ll ans=1,pow2=1;

int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++) pow2=(pow2*2)%mod;
    for(int i=1;i<=n;i++) ans=(ans*(pow2-i))%mod;
    printf("%lld\n",ans);
    return 0;
}
posted @ 2020-10-07 13:52  jasony_sam  阅读(132)  评论(0编辑  收藏  举报