大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足

的序列.

刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$在加上矩阵幂的复杂度显然不行.

看了题解发现可以按每位单独来考虑.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head ll n, k, l, m; struct Mat {
int v[4][4];
Mat() {memset(v, 0, sizeof v);}
Mat operator * (const Mat& b) const {
Mat c;
REP(k,0,3) REP(i,0,3) REP(j,0,3) {
c.v[i][j] = ((ll)v[i][k]*b.v[k][j]+c.v[i][j])%m;
}
return c;
}
Mat operator ^ (ll nn) {
Mat b, a=*this;
REP(i,0,3) b.v[i][i]=1;
while(nn) {
if(nn&1LL) b=b*a;
nn>>=1LL,a=a*a;
}
return b;
}
}; int main() {
cin>>n>>k>>l>>m;
if (m==1||l<64&&(k>>l)) return puts("0"),0;
Mat g;
g.v[0][0]=g.v[0][2]=g.v[1][1]=g.v[1][3]=g.v[2][0]=g.v[3][1]=g.v[3][2]=g.v[3][3]=1;
g = g^n;
int x = (g.v[0][0]+g.v[2][0])%m, y = (g.v[1][0]+g.v[3][0])%m;
ll ans = 1;
REP(i,0,l-1) {
if (k>>i&1) ans = ans*y%m;
else ans = ans*x%m;
}
printf("%lld\n", ans);
}

GukiZ and Binary Operations CodeForces - 551D (组合计数)的更多相关文章

  1. Codeforces 551D GukiZ and Binary Operations(矩阵快速幂)

    Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的 ...

  2. Codeforces 551 D. GukiZ and Binary Operations

    \(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) ...

  3. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations 矩阵快速幂优化dp

    D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. D. GukiZ and Binary Operations(矩阵+二进制)

    D. GukiZ and Binary Operations   We all know that GukiZ often plays with arrays. Now he is thinking ...

  5. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)

    题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...

  6. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations

    得到k二进制后,对每一位可取得的方法进行相乘即可,k的二进制形式每一位又分为2种0,1,0时,a数组必定要为一长为n的01串,且串中不出现连续的11,1时与前述情况是相反的. 且0时其方法总数为f(n ...

  7. Intercity Travelling CodeForces - 1009E (组合计数)

    大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...

  8. Yet Another Problem On a Subsequence CodeForces - 1000D (组合计数)

    大意:定义一个长为$k>1$且首项为$k-1$的区间为好区间. 定义一个能划分为若干个好区间的序列为好序列. 给定序列$a$, 求有多少个子序列为好序列. 刚开始一直没想出来怎么避免重复计数, ...

  9. Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)

    大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...

随机推荐

  1. linux查看当前目录

    查看当前路径命令:pwd pwd命令能够显示当前所处的路径. 这个命令比较简单,如果有时在操作过程中忘记了当前的路径,则可以通过此命令来查看路径,其执行方式为:

  2. 使用io/ioutil进行读写文件

    读文件: package main import ( "fmt" "io/ioutil" ) func main() { b, err := ioutil.Re ...

  3. [log4j]Error:The method getLogger(String) in the type Logger is not applicable for the arguments

    原因:本该导入import org.apache.log4j.Logger; 结果成了import java.util.logging.Logger; 如果硬把private static Logge ...

  4. 在Eclipse中使用WindowBuilder设计Swing程序

    在Eclipse中使用WindowBuilder设计Swing程序     Swing程序表示Java的客户端窗体程序,除了通过手动编写代码的方式设计Swing程序之外,Eclipse中还提供了一种W ...

  5. Ubuntu16.04.3安装并配置samba方法

    目的:单个Linux用户可以在windows电脑上通过映射网络驱动器的方式来访问自己的工作目录. 方法如下: 1.安装smb服务器:apt-get install samba2.安装smb支持的文件系 ...

  6. 魔法方法 __slots__ 方法

    场景解析 网游的用户, 大量的用户本质都是类的实例化对象, 在线人数百万级时对内存是很大的挑战, 如何减少这部分的内存 方法解析 __slots__ 方法 取消默认的类实例中的  __dict__  ...

  7. Java之分布式事务TCC

    看这个博客吧! 挺好的. 理论:https://www.cnblogs.com/jajian/p/10014145.html 实践:https://www.cnblogs.com/sessionbes ...

  8. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用

    笔记 5.PageHelper分页插件使用     简介:讲解开源组件,mybaits分页插件的使用 1.引入依赖             <!-- 分页插件依赖 -->          ...

  9. WebSocket 搭建简单聊天网站

    HTML5 WebSocket WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 在WebSocket API中,浏览器和服务器只需要做一个握手的动作,然后,浏 ...

  10. 【转】ffluos编译

    FluffOS是在MUDOS基础上更新完成的.进行了许多新功能和bug修复. 针对LPC有很好的兼容性,如果你的MUD运行MUDOS V22+版本,可以很容易运行在fluffos上. 系统环境: Cn ...