Not Wool Sequences(CF-239C)

Problem Description

A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.

The expression  means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor".

In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).


The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).


Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.



3 2




Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).

Question meaning: given the two numbers of N and m, now we need to take the repeatable n numbers from 0~2^m-1, so that the sum of the sequence exclusive or is 0, and ask how many of the 2^m-1 sequences meet the requirements.

Train of thought:

Let's set a prefix array so that sum[i]=sum[i-1]^a[i], then a[i]=sum[i-1]^sum[i]

Assuming that 0~2^m-1 is not a sequence that meets the requirements, then a[l]^a[l+1]^...^a[r]!=0, that is, sum[l-1]^sum[r]!=0

Because l<=r, all numbers in the sum array need to be twofold different

Because a[i]=sum[i-1]^sum[i], the value of sum[i] is [1,2^m]

Therefore, the question becomes how many arrays of length n are found, and the numbers in the arrays are different between [1,2^m].

Source Program

#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+9;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main(){
    LL n,m;
    LL mul=1,res=1;
    for(int i=1;i<=m;i++)
    for(int i=1;i<=n;i++)
	return 0;


Tags: Programming Java

Posted on Fri, 11 Oct 2019 08:55:45 -0700 by shatner