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
6
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).
从这题学到了一个小技巧:处理一串数的抑或,可以像前缀和那样先预处理出前缀的抑或值,然后再枚举端点就可以得到任意一段的抑或值。然后这题要求任意一段的抑或都不相等,也就是前缀抑或数组b中不能有相等的元素,因为b中每个数的取值范围都是1~2^m-1(根绝题目条件,任何一个数都不能取0),且任意给b赋值,原来的数组a都一定存在一个唯一解,即一一对应关系。这样答案就是排列数A(2^m-1,n).
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
typedef long long LL;
const int maxn = 3000 + 5;
const int INF = 100000;
const int Mod = 1000000000 + 9;
LL cal(LL x){
LL ret = 1;
while(x > 30){
ret = (((LL)1 << 30) * ret) % Mod;
x -= 30;
}
ret = (((LL)1 << x) * ret) % Mod;
return ret;
}
int main(){
LL n,m;
while(cin >> n >> m){
LL ans = 1;
LL pow = cal(m);
for(LL i = 1;i <= n;i++){
ans = (ans * (pow - i)) % Mod;
}
cout << ans << endl;
}
return 0;
}
本文介绍了一种计算特定长度及数值范围内非羊毛序列数量的方法。羊毛序列是指包含一段连续子序列,其异或值为0的整数序列。文中提供了一个高效的算法实现,并通过样例解释了计算原理。
6466

被折叠的 条评论
为什么被折叠?



