Axel and Marston in Bitland CodeForces - 782F (bitset优化)
$dp[0/1][i][x][y]$表示起始边为0/1, 走$2^i$ 步, 是否能从$x$走到$y$
则有转移方程
$dp[z][i][x][y]\mid=dp[z][i-1][x][k]\&dp[z\wedge1][i-1][k][y]$
复杂度 $O(k_0n^3)$, 其中$k_0=log(1e18)$
这里可以用bitset优化第四维的递推, bitset底层相当于若干个64bit数, 可以优化64的常数
复杂度$O(\frac{k_0n^3}{\omega})$
#include <iostream>
#include <bitset>
#include <cstdio>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll; int n, m;
bitset<> f[][][], pre, now; int main() {
scanf("%d%d", &n, &m);
REP(i,,m) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
f[w][][u][v] = ;
}
REP(i,,) REP(z,,) REP(x,,n) REP(y,,n) {
if (f[z][i-][x][y]) f[z][i][x]|=f[z^][i-][y];
}
ll ans = , z = ;
pre[] = ;
PER(i,,) {
now.reset();
REP(j,,n) if (pre[j]) now|=f[z][i][j];
if (now.count()) z^=, ans^=1ll<<i, pre=now;
}
printf("%lld\n",ans>1e18?-:ans);
}
Axel and Marston in Bitland CodeForces - 782F (bitset优化)的更多相关文章
- CF781D Axel and Marston in Bitland [倍增 矩阵乘法 bitset]
Axel and Marston in Bitland 好开心第一次补$F$题虽然是$Div.2$ 题意: 一个有向图,每条边是$0$或$1$,要求按如下规则构造一个序列然后走: 第一个是$0$,每次 ...
- Codeforces 781D Axel and Marston in Bitland 矩阵 bitset
原文链接https://www.cnblogs.com/zhouzhendong/p/CF781D.html 题目传送门 - CF781D 题意 有一个 n 个点的图,有 m 条有向边,边有两种类型: ...
- Codeforces 781D Axel and Marston in Bitland
题目链接:http://codeforces.com/contest/781/problem/D ${F[i][j][k][0,1]}$表示是否存在从${i-->j}$的路径走了${2^{k}} ...
- CodeForces 781D Axel and Marston in Bitland DP
题意: 有一个\(n\)个点\(m\)条边的无向图,边有两种类型,分别用\(0\)和\(1\)标识 因此图中的任意一条路径都对应一个\(01\)字符串 定义一个无限长的字符串\(s\): 开始令\(s ...
- codeforces781D Axel and Marston in Bitland
题目链接:codeforces781D 正解:$bitset$+状压$DP$ 解题报告: 考虑用$f[t][0.1][i][j]$表示从$i$出发走了$2^t$步之后走到了$j$,且第一步是走的$0$ ...
- Codeforces 788C The Great Mixing(背包问题建模+bitset优化或BFS)
[题目链接] http://codeforces.com/problemset/problem/788/C [题目大意] 给出一些浓度的饮料,要求调出n/1000浓度的饮料,问最少需要多少升饮料 [题 ...
- Codeforces 566E - Restoring Map(bitset 优化构造)
Codeforces 题目传送门 & 洛谷题目传送门 本来说好的不做,结果今早又忍不住开了道题/qiao 我们称度为 \(1\) 的点为叶节点,度大于 \(1\) 的点为非叶节点. 首先考虑如 ...
- Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间
D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...
- Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...
随机推荐
- Java设计模式应用——桥接模式
性能管理系统中,数据产生后需要经过采集,汇聚,入库三个流程,用户才能查询使用. 采集可以是snmp采集,也可以是ems采集:汇聚可以使storm汇聚,也可以是spark汇聚:入库可以是hdfs入库,也 ...
- Hive 复制分区表和数据
1. 非分区表: 复制表结构: create table new_table as select * from exists_table where 1=0; 复制表结构和数据: create tab ...
- outlook还原初始设置
找到outlook的安装地址: C:\Program Files\Microsoft Office\Office15 进入命令行界面 WIN+R ->cmd cd C:\Program File ...
- 有趣的js匿名函数写法(function嵌套)
例子没有什么实际意义,只能做为思路参考 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&quo ...
- Linux学习笔记之Linux Centos关闭防火墙
# Centos6.x /etc/init.d/iptables stop chkconfig iptables off sed -i 's/SELINUX=enforcing/SELINUX=dis ...
- ELK学习笔记之ElasticSearch的索引详解
0x00 ElasticSearch的索引和MySQL的索引方式对比 Elasticsearch是通过Lucene的倒排索引技术实现比关系型数据库更快的过滤.特别是它对多条件的过滤支持非常好,比如年龄 ...
- oracle、Mysql数据库客户端DbVisualizer安装
原文链接:https://jingyan.baidu.com/article/454316ab675302f7a7c03a9e.html
- Asterisk1.8 sip编码协商分析
在开始分析之前,先对编码协商中可能涉及的asterisk数据结构和变量作些说明.ast_channel:定义一个通用的通道数据结构 struct ast_channel { const struct ...
- VC++使用IMAPI调用Outlook邮箱客户端和Foxmail邮箱客户端遇到的问题
http://www.cnblogs.com/abiao/articles/303090.html 发送邮件 MAPISendMail() 发送邮件功能就是对MAPISendMail()的封装.下面解 ...
- Win32 实现 MFC CFileDialog 对话框
void CWriteWnd::OpenFileDialog() { OPENFILENAME ofn; TCHAR szFile[MAX_PATH] = _T(""); Zero ...