题目链接:点击查看

题目大意:给出一个限制 d 与模数 mod ,求出可以构造出的满足条件的数组 a 的个数,需要满足以下条件:

  1. 数组 a 的长度大于等于 1
  2. 数组 a 严格递增
  3. 数组 a 的最小值大于等于 1 ,数组 a 的最大值小于等于 d
  4. 对于数组 a ,构造出一个数组 b :
    1. i == 1 时:b[ 1 ] = a[ 1 ]
    2. i > 1 时:b[ i ] = b[ i - 1 ] ^ a[ i ]
  5. 数组 b 严格递增

题目分析:1900分的组合数学问题,直接扔给队友去做了,赛后补题好歹算是学会了,数学渣真的没办法呀

通过观察或者适当猜测,可以看出这个问题是一个基于位运算的题目,换句话说,如果在数组 a 中选择了 2 ,接下来就没法选择 3,如果选择了 4 ,接下来就没办法选择 5 6 7,选择了 8 ,接下来就没法选择 9 10 11 12 13 14 15 ,也就是说对于 a[ i ] 的每个数字而言,其二进制中最高位的那个 1 的位置一定是唯一的,且是递增的

有了这个结论之后就不难实现了,对于每个二进制的 i 来说,我们可以选择的数字有种,需要注意的是我们还需要加入一种情况,那就是第 i 个位置不选择数字的情况,也就是对于每个 i 的方案数变成了种情况了,累乘一下就行了,最后需要减去一,这个一代表的是所有位置都不选的情况,然后注意特判一下 n 就好了

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=2e5+100;int main()
{
#ifndef ONLINE_JUDGE
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
//  ios::sync_with_stdio(false);int w;cin>>w;while(w--){int n,mod;scanf("%d%d",&n,&mod);LL ans=1;for(int i=0;i<30;i++){if((1<<i)>n)break;ans=(ans*(min((1<<(i+1))-1,n)-(1<<i)+2))%mod;}ans=(ans+mod-1)%mod;printf("%lld\n",ans);}return 0;
}

CodeForces - 1330D Dreamoon Likes Sequences(组合数学)相关推荐

  1. Dreamoon Likes Sequences CodeForces - 1330D(组合数学+位运算)

    Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find i ...

  2. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...

  3. D. Dreamoon Likes Sequences(异或)

    Problem - 1330D - Codeforces 题意: 给你两个整数d,m,找出数组a的数量,满足以下约束. a的长度为n,n≥1 1≤a1<a2<⋯<an≤d 定义长度为 ...

  4. Codeforces Round #631 (Div. 2) C. Dreamoon Likes Coloring 构造

    传送门 文章目录 题意: 思路: 题意: 思路: 针灸思维不行,数据结构来凑呗. 一开始做的时候想简单了,一直wawawa,后来想到了hackhackhack样例,开始换思路构造,结果死活想不到O(m ...

  5. Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)

    Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty ( ...

  6. D - Yet Another Problem On a Subsequence CodeForces - 1000D (DP,组合数学)

    D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2 ...

  7. Codeforces 447C - DZY Loves Sequences

    447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...

  8. codeforces 450B. Jzzhu and Sequences 解题报告

    题目链接:http://codeforces.com/problemset/problem/450/B 题目意思:给出 f1 和 f2 的值,以及n,根据公式:fi = fi-1 + fi+1,求出f ...

  9. Codeforces - 466C - Number of Ways - 组合数学

    https://codeforces.com/problemset/problem/466/C 要把数据分为均等的非空的三组,那么每次确定第二个分割点的时候把(除此之外的)第一个分割点的数目加上就可以 ...

最新文章

  1. 给python点颜色青少年学编程_早晨送给自己的句子,句句经典励志!
  2. Python入门100题 | 第031题
  3. 人才管理是什么意思_cms系统是什么意思,国内常用的cms内容管理系统有哪些
  4. python的作者叫什么_作者的来历是什么?
  5. linux安装.AppImage后缀安装包
  6. 运维小白死磕的专业术语,你真的理解透了吗?
  7. Spring AOP AspectJ 代码实例
  8. 谷歌浏览器jsonView下载及安装
  9. git提交代码时遇到代码库有更新以及本地有更新的解决方法
  10. js禁止苹果页面底部滚动_js禁止页面滚动
  11. enum ordinal_Java Enum ordinal()方法与示例
  12. 不能显示隐藏文件解决方法
  13. python自动化配置路由器_使用Python管理小米路由器
  14. Proteus,keil5仿真运行stm32程序,流水灯详细教程
  15. 儿子于靖洋15个月照片
  16. 哈希传递PTH、密钥传递PTT、票据传递PTK的实现和比较
  17. 小程序根据不同用户,显示不同tabBar
  18. H264系列(5):关于ITU-H264 和 ISO/IEC H264 的关系
  19. 处理Maven本地仓库.lastUpdated文件
  20. IC卡·一卡一密加密 动态数据防伪方案实现

热门文章

  1. SpringSecurity 案例之创建资源服务器准备工作
  2. 使用Docker-数据卷挂载案例1
  3. 初识Docker-Docker架构
  4. zookeeper的设计猜想-防止单点故障
  5. volatile 关键字是如何保证可见性的?
  6. 搭建基础架构-ResultMsg
  7. SpringCloud微服务带来的问题
  8. 运行配置文件中指定类的指定方法
  9. 关于Spring AOP代理的生成过程
  10. RequestMapping介绍