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).
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
3 2
Output
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 個數,使得組成的序列異或和為 0,問這 2^m-1 個數中組成的序列有多少個滿足要求
思路:
設一個前綴數組,使得 sum[i]=sum[i-1]^a[i],那么 a[i]=sum[i-1]^sum[i]
假設 0~2^m-1 不是一個滿足要求的序列,那么 a[l]^a[l+1]^...^a[r]!=0,即有:sum[l-1]^sum[r]!=0
由于 l<=r,因此 sum 數組中的所有數需要兩兩不同
又因為 a[i]=sum[i-1]^sum[i],因此 sum[i] 的取值在 [1,2^m]
因此,問題就變成求有多少個長度為 n 的數組,且數組中的數在 [1,2^m] 之間且不相同
Source Program
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #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;scanf("%lld%lld",&n,&m);LL mul=1,res=1;for(int i=1;i<=m;i++)mul=(mul*2)%MOD;for(int i=1;i<=n;i++)res=(res*(mul-i))%MOD;printf("%lld\n",res);return 0; }?
總結
以上是生活随笔為你收集整理的Not Wool Sequences(CF-239C)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 愤怒的牛(信息学奥赛一本通-T1433)
- 下一篇: 训练日志 2019.1.23