CF 1329B Dreamoon Likes Sequences
2024-10-09 12:11:59
题目:
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers d,m find the number of arrays a, satisfying the following constraints:
- The length of a is n, n≥1
- 1≤a1<a2<⋯<an≤d
- Define an array b of length n as follows: b1=a1, ∀i>1,bi=bi−1⊕ai, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b1<b2<⋯<bn−1<bn should hold.
Since the number of possible arrays may be too large, you need to find the answer modulo m.
思路:容易想到如果两个数二进制的最高位都是1,则两者"^"后者数值一定比前者小,可以推断出"2^0 ~ 2^1 - 1","2^1 ~ 2^2 - 1",...,"2^(n-1) ~ 2^(n) - 1"为不同集合,我们只需要统计出每个集合的个数,然后求出组合方案数就行。
#include<iostream>
#include<string>
#include<vector>
#include<cstdio> #define ll long long
#define pb push_back using namespace std; const int N = 1e6 + ;
vector<ll > a;
ll p[N];
ll ans, MOD; void init()
{
int x = ;
while(){
p[x] = ( << x) - ;
if(p[x] > 1e9) break;
x++;
}
} void solve()
{ init(); int T;
cin >> T;
while(T--){ ans = ;
a.clear(); ll n;
cin >> n >> MOD; int inx = -;
for(int i = ; i < ; ++i){
if(n >= p[i]) a.pb(p[i] - p[i - ]);
else{
inx = i;
break;
}
} if(n - p[inx - ] > ) a.pb(n - p[inx - ]);
for(auto x : a){
ans = (ans * (x + )) % MOD;
} ans = (ans - + MOD) % MOD; //cout << "(ans = " << ans << ")" << endl;
cout << ans << endl;
}
} int main() { ios::sync_with_stdio(false);
cin.tie();
cout.tie();
solve();
//cout << "ok" << endl;
return ;
}
最新文章
- Allegro之Enhance pad Entry(增强焊盘进入约束功能)的使用
- SQL Server 聚合函数算法优化技巧
- 展讯camera去除尺寸相关缓存
- UNIX环境高级编程笔记之标准I/O库
- 第二百七十九天 how can I 坚持
- Cocos2d-x实例:单点触摸事件
- MySQL - 启停服务
- php框架练习
- 动态规划---最长上升子序列问题(O(nlogn),O(n^2))
- zoj 2402 - Lenny&;#39;s Lucky Lotto Lists
- 记一次 bug 修复 , 未将对象引用实例化
- 引导加载程序之争: LILO 和 GRUB
- 初级Django学习
- Windows 7无声音的解决方案
- table增删改查操作--jq
- Map的嵌套使用
- javascript简单的选项卡
- eclipse下查看java源码设置
- ArduinoYun教程之Arduino编程环境搭建
- 用UIInterpolatingMotionEffect产生透视效果