题面

Bzoj

Sol

状压很显然

重点在于转移:题目就相当与每\(p\)长度的车站必须有且仅有\(k\)个被经过

那么转移时状压的二进制一定要有\(k\)个一

且两个相邻转移的状态之间必须满足:设为\(i->j\),则\((i >> 1) \&j\)要有\(k-1\)个\(1\)

然后就可以加上矩阵快速幂优化,注意把满足要求的状态记下来,只有一百多个

我常数丑是我的错

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int Zsy(30031); IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, k, p, cnt[1024], que[150], len, pos; IL void Up(RG int &x, RG int y){
x += y;
if(x >= Zsy) x -= Zsy;
} struct Matrix{
int a[150][150]; IL Matrix(){
Fill(a, 0);
} IL int* operator [](RG int x){
return a[x];
} IL void Init(){
for(RG int i = 0; i < len; ++i) a[i][i] = 1;
} IL Matrix operator *(RG Matrix B){
RG Matrix C;
for(RG int i = 0; i < len; ++i)
for(RG int j = 0; j < len; ++j)
for(RG int l = 0; l < len; ++l)
Up(C[i][l], 1LL * a[i][j] * B[j][l] % Zsy);
return C;
}
} S, E, T; int main(RG int argc, RG char* argv[]){
n = Input(), k = Input(), p = Input();
for(RG int i = 0; i < (1 << p); ++i){
for(RG int x = i; x; x -= x & -x) ++cnt[i];
if(cnt[i] == k && (i & 1)) que[len++] = i;
}
for(RG int i = 0; i < len; ++i)
if(que[i] == (1 << k) - 1) pos = i;
for(RG int i = 0; i < len; ++i)
for(RG int j = 0; j < len; ++j)
if(cnt[(que[i] >> 1) & que[j]] == k - 1) T[i][j] = 1;
E.Init(), S[0][pos] = 1;
for(RG int i = n - k; i; i >>= 1, T = T * T)
if(i & 1) E = E * T;
S = S * E;
printf("%d\n", S[0][pos]);
return 0;
}

[HNOI2010]BUS 公交线路的更多相关文章

  1. 【BZOJ2004】[Hnoi2010]Bus 公交线路 状压+矩阵乘法

    [BZOJ2004][Hnoi2010]Bus 公交线路 Description 小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依次编号为1到N,相邻公交车站间的距离均为1 ...

  2. 【BZOJ2004】[HNOI2010]Bus 公交线路

    [BZOJ2004][HNOI2010]Bus 公交线路 题面 bzoj 洛谷 题解 $N$特别大$P,K$特别小,一看就是矩阵快速幂+状压 设$f[S]$表示公交车状态为$S$的方案数 这是什么意思 ...

  3. bzoj 2004: [Hnoi2010]Bus 公交线路

    Description 小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依次编号为1到N,相邻公交车站间的距 离均为1km. 作为公交车线路的规划者,小Z调查了市民的需求,决 ...

  4. BZOJ2004:[HNOI2010]Bus 公交线路(状压DP,矩阵乘法)

    Description 小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依次编号为1到N,相邻公交车站间的距离均为1km. 作为公交车线路的规划者,小Z调查了市民的需求,决定 ...

  5. 【bzoj2004】[Hnoi2010]Bus 公交线路 状压dp+矩阵乘法

    题目描述 小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依次编号为1到N,相邻公交车站间的距离均为1km. 作为公交车线路的规划者,小Z调查了市民的需求,决定按下述规则设计 ...

  6. [bzoj2004] [洛谷P3204] [Hnoi2010] Bus 公交线路

    Description 小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依次编号为1到N,相邻公交车站间的距 离均为1km. 作为公交车线路的规划者,小Z调查了市民的需求,决 ...

  7. [BZOJ 2004] [Hnoi2010] Bus 公交线路 【状压DP + 矩阵乘法】

    题目链接: BZOJ - 2004 题目分析 看到题目完全不会..于是立即看神犇们的题解. 由于 p<=10 ,所以想到是使用状压.将每个连续的 p 个位置压缩成一个 p 位 2 进制数,其中共 ...

  8. BZOJ 2004: [Hnoi2010]Bus 公交线路 [DP 状压 矩阵乘法]

    传送门 题意: $n$个公交站点,$k$辆车,$1...k$是起始站,$n-k+1..n$是终点站 每个站只能被一辆车停靠一次 每辆车相邻两个停靠位置不能超过$p$ 求方案数 $n \le 10^9, ...

  9. 【BZOJ 2004】: [Hnoi2010]Bus 公交线路

    题目链接: TP 题解:   所以说,超显眼的数据范围啊. 很显然我们对于每个P的区间都是要有k个站被bus停留,然后考虑转移的话应该是把这k个站里的某个bus往前走,那么转移也很显然了,n的范围很大 ...

  10. BZOJ2004: [Hnoi2010]Bus 公交线路

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2004 状压dp+矩阵乘法. f[i][s]表示从第i位至前面的i-k位,第i位必须取的状态. ...

随机推荐

  1. HTTP入门

    请求报文图解: 请求报文 图片 响应报文图解: 响应报文  

  2. IDEA的优质使用博客资源

    intelliJ idea 使用技巧&方法 IntelliJ IDEA 常用设置讲解 IntelliJ IDEA 详细图解最常用的配置 ,适合刚刚用的新人. IntelliJ IDEA 常见文 ...

  3. 2个域名重定向到https域名

    配置实例: [root@iZbp17q09o7e8pgg9dybd7Z conf.d]# cat company.confserver { listen 80; server_name www.yu* ...

  4. css里面如何设置body背景图片满屏

    @{    Layout = null;    ViewBag.Title = "Login Page";} <!DOCTYPE html> <html>& ...

  5. CENTOS6.6下redis3.2集群搭建

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn [参考:]http://blog.csdn.net/zhu_tian ...

  6. eclipse 使 用Ctrl+鼠标左键进入mapper.xml文件的方法

    在 >eclipse MarketPlace中下载>Mybatipse 插件安装重启即可完成

  7. 买帽子 (hash)

    思路:表示数字i出现的次数,在输入的同时记录每个数字出现的次数.最后从0枚举到1000判断第三个是否存在,存在则记录该数字. #include <stdio.h> #include < ...

  8. 独立游戏大电影 原名(Indie.Game)

    电影链接 独立游戏大电影 感觉很不错呢!!

  9. php面试上机题(2018-3-3)

    需求:将第三方api的前3000条数据全部读取出来,存入对应的数据库字段 第三方api:http://pub.cloudmob.mobi/publisherapi/offers/?uid=92& ...

  10. kibana常用聚合查询DSL语句记录

    -------- GET winlogbeat-2017.11.*/_search { "query": { "bool": { "must" ...