JZOJ 4250.路径
\(\text{Solution}\)
\(30\) 分暴搜合法路径
另 \(30\) 分状压
设 \(f_{i,j,k}\) 表示当前到第 \(i\) 个点,走过的点状态为 \(j\),走过的路径长度为 \(k\) 的方案数
\(100\) 分仍然回到暴搜
考虑折半搜索,把路径拼起来,先搜一次,哈希表记下 \(f_{i,j,k}\),再搜一次,因为是无向图,可以都从 \(1\) 开始,统计答案
\(\text{Code}\)
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC optimize("fast-math","unroll-loops","no-stack-protector","inline")
#include<cstdio>
#define re register
using namespace std;
typedef long long ll;
const int mod = 19260817;
int n, l, ans, a[20][20], lim, MS;
struct node{
int x, s, len, nxt, f;
}e[mod + 5];
int h[mod + 5], tot;
inline void modify(int x, int s, int len)
{
int key = (21474836470000ll * x + 1000000007ll * s + 1009ll * len) % mod;
for(re int i = h[key]; i; i = e[i].nxt)
if (e[i].x == x && e[i].s == s && e[i].len == len) return (void)++e[i].f;
e[++tot] = node{x, s, len, h[key], 1}, h[key] = tot;
}
inline int query(int x, int s, int len)
{
int key = (21474836470000ll * x + 1000000007ll * s + 1009ll * len) % mod;
for(re int i = h[key]; i; i = e[i].nxt)
if (e[i].x == x && e[i].s == s && e[i].len == len) return e[i].f;
return 0;
}
void dfs1(int x, int s, int len, int num)
{
if (num >= lim) return modify(x, s, len);
for(re int i = 2; i <= n; i++)
if (!((s >> (i - 1)) & 1) && len + a[x][i] <= l)
dfs1(i, s + (1 << (i - 1)), len + a[x][i], num + 1);
}
void dfs2(int x, int s, int len, int num)
{
if (num >= n - lim)
return void(ans += query(x, (MS ^ (s - (1 << (x - 1)))) - 1, l - len));
for(re int i = 2; i <= n; i++)
if (!((s >> (i - 1)) & 1) && len + a[x][i] <= l)
dfs2(i, s + (1 << (i - 1)), len + a[x][i], num + 1);
}
int main()
{
freopen("way.in", "r", stdin);
freopen("way.out", "w", stdout);
scanf("%d%d", &n, &l);
for(re int i = 1; i <= n; i++)
for(re int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
lim = n >> 1, MS = (1 << n) - 1, dfs1(1, 0, 0, 0), dfs2(1, 0, 0, 0);
printf("%d", ans);
}
JZOJ 4250.路径的更多相关文章
- JZOJ.5234【NOIP2017模拟8.7】外星人的路径
Description 有一个外星人控制了你的大脑.一开始你处于原点(0,0).外星人有一个由(R,U,D,L)组成的长度为M 的操作序列,分别代表(右,上,下,左).平面上有N 个关键点,每当外星人 ...
- [jzoj]2505.【NOIP2011模拟7.29】藤原妹红
Link https://jzoj.net/senior/#main/show/2505 Description 在幻想乡,藤原妹红是拥有不老不死能力的人类.虽然不喜欢与人们交流,妹红仍然保护着误入迷 ...
- [jzoj]3875.【NOIP2014八校联考第4场第2试10.20】星球联盟(alliance)
Link https://jzoj.net/senior/#main/show/3875 Problem 在遥远的S星系中一共有N个星球,编号为1…N.其中的一些星球决定组成联盟,以方便相互间的交流. ...
- JZOJ 5602.【NOI2018模拟3.26】Cti
JZOJ 5602.[NOI2018模拟3.26]Cti Description 有一个 \(n×m\) 的地图,地图上的每一个位置可以是空地,炮塔或是敌人.你需要操纵炮塔消灭敌人. 对于每个炮塔都有 ...
- [jzoj]1729.blockenemy
Link https://jzoj.net/senior/#main/show/1729 Description 你在玩电子游戏的时候遇到了麻烦...... 你玩的游戏是在一个虚拟的城市里进行,这个城 ...
- JZOJ 5919. 逛公园
Description 琥珀色黄昏像糖在很美的远方,思念跟影子在傍晚一起被拉长……Description 小 B 带着 GF 去逛公园,公园一共有 n 个景点,标号为 ...
- [jzoj 3175] 数树数 解题报告 (树链剖分)
interlinkage: https://jzoj.net/senior/#main/show/3175 description: 给定一棵N 个节点的树,标号从1~N.每个点有一个权值.要求维护两 ...
- [jzoj 5926] [NOIP2018模拟10.25] naive 的图 解题报告(kruskal重构树+二维数点)
题目链接: https://jzoj.net/senior/#main/show/5926 题目: 题解: 显然最小的最大路径在最小生成树上(最小生成树=最小瓶颈生成树) 于是我们建出kruskal重 ...
- [JZOJ NOIP2018模拟10.21]
考试之前我刚刚领略到了特判的重要性,没想到T2的两个子任务还是写挂了,丢了20分 考试的感觉不行,一路打的都是暴力,正解的思路想到一半就断了推不下去 T1:逛公园 题目链接: https://jzoj ...
- [JZOJ 5895] [NOIP2018模拟10.5] 旅游 解题报告 (欧拉回路+最小生成树)
题目链接: https://jzoj.net/senior/#main/show/5895 题目: 题解: 有一个好像比较显然的性质,就是每条边最多经过两次 那么我们考虑哪些边需要经过两次.我们把需要 ...
随机推荐
- mongorestore target dump invalid CreateFile dump The system cannot find
问题 使用 mongorestore 指定 dump 文件夹,恢复数据报错. mongorestore target 'dump' invalid: CreateFile dump: The syst ...
- Excel2010表格内容被加密,无法编辑内容。
Sub PasswordBreaker() Dim i As Integer, j As Integer, k As Integer Dim l As Integer, m As Integer, n ...
- 【Java SE进阶】Day12 函数式接口、函数式编程(Lambda表达式)
一.函数式接口介绍 1.概念 仅有一个抽象方法的接口 适用于函数式编程(Lambda使用的接口) 语法糖:方便但原理不变,如for-each是Iterator的语法糖 Lambda≈匿名内部类的语法糖 ...
- 【Shell脚本案例】案例3:批量创建100个用户并设置密码
一.背景 新入职员工创建用户 二.常规操作 useradd zhangsan ls /home/ password zhangsan 三.考虑问题 1.实现自动输入密码,将其存到文件中 passwor ...
- python random模块几个常用方法
python random模块几个常用方法 random.random()方法 random.uniform(a, b)方法 random.randint(a, b)方法 random.randran ...
- 深度学习GPU加速配置方法
深度学习GPU加速配置方法 一.英伟达官方驱动及工具安装 首先检查自己的电脑驱动版本,未更新至最新建议先将驱动更新至最新,然后点击Nvidia控制面板 2.在如下界面中点击系统信息,点击显示可以看见当 ...
- vue 项目引入 echarts折线图
一.components文件下新建 lineCharts.vue <template> <div :class="className" :style=" ...
- curl请求https报错
curl 一般情况下请求http时不会有问题 但是请求 https 协议的链接时会报错,如下: curl: (60) SSL certificate problem: unable to get lo ...
- Linux的串口非标准波特率设置更改
用的是全志的R528 SDK,Linux内核是5.4,新增加一个250000的非标准波特率 参考网络大神文档,实践并记录宝贵的经验. 方法: 1.修改内核的/include/uapi/asm-gene ...
- vue-3 this概念
一.this概念 官方是这样说的: 在 setup()内部,this 不会是该活跃实例的引用 因为 setup() 是在解析其它组件选项之前被调用的,所以 setup() 内部的 this 的行为与其 ...