题目C. Not Wool Sequences
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
Input
The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).
Output
Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.
Examples
input
Copy
3 2
output
Copy
6
Note
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).
题意给出两个数n,m从0~2^m-1个数中找出n个数使其组成非羊毛序列(羊毛序列就是存在一个子序列连续异或等于零)问一共有多少种非羊毛序列输出他的种数。
这是一道找规律的题
1 2 3种
2 2 6种3*2
3 2 6种3*2*1
4 2 0种3*2*1*0
1 3 7种
2 3 42种7*6
3 3 210种7*6*5
4 3 840中7*6*5*4
规律很显然就是阶乘.
#include<string.h>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
long long inf=1e9+9;
int kuai(long long n)
{
long long nn=1,k=2;
for(;n;n>>=1)
{
if(n&1)
nn=(long long)nn*k%inf;
k=(long long)k*k%inf;
}
return nn;
}
int main()
{
long long n,k,m;
cin>>n>>m;
long long ans=kuai(m)-1,cnt=kuai(m);
for(int i=1;i<=n-1;i++)
{
ans=ans*(cnt-1-i)%inf;
}
cout<<(ans+inf)%inf<<endl;
}