JZOJ 5459. 【NOIP2017提高A组冲刺11.7】密室
5459. 【NOIP2017提高A组冲刺11.7】密室
(File IO): input:room.in output:room.out
Description
密室中有N 个房间,初始时,小X 在1 号房间,而出口在N 号房间。
密室的每一个房间中可能有着一些钥匙和一些传送门,一个传送门会单向地创造一条从房间X 到房间Y 的通道。另外,想要通过某个传送门,就必须具备一些种类的钥匙(每种钥匙都要有才能通过)。幸运的是,钥匙在打开传送门的封印后,并不会消失。
然而,通过密室的传送门需要耗费大量的时间,因此,小X 希望通过尽可能少的传送门到达出口,你能告诉小X 这个数值吗?
另外,小X 有可能不能逃出这个密室,如果是这样,请输出"No Solution"。
Input
接下来N 行,每行K 个0 或1,若第i 个数为1,则表示该房间内有第i 种钥匙,若第i 个数为0,则表示该房间内没有第i 种钥匙。
接下来M 行,每行先读入两个整数X,Y,表示该传送门是建立在X 号房间,通向Y 号房间的,再读入K 个0 或1,若第i 个数为1,则表示通过该传送门需要i 种钥匙,若第i 个数为0,则表示通过该传送门不需要第i 种钥匙。
Output
Sample Input
3 3 2
1 0
0 1
0 0
1 3 1 1
1 2 1 0
2 3 1 1
Sample Output
2
Data Constraint
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnMAAABvCAIAAAAIWdGQAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABD/SURBVHhe7Z2/ixtJFsfn3+h40smcbdSREidOnFzQgZINJrugQcGBc4HgYCNDw7CwsGAaDE4WgXCycAwo20AoM8ugxIERYjGDEb6qftVSVfUPzXnGt/2++n6irm55keazr15XdXW9i6+EEEIIeTqYWQkhhJCnhJmVEEIIeUqYWQkhhJCn5JhZLwghhBDyrbhsGo1Z/QtkaNAONvSLDf1iE/kNG3Q/YGgHG/rFhn6xYWbVCu1gQ7/Y0C82zKxaoR1s6Bcb+sWGmVUrtIMN/WJDv9hAZtbtevG2LPL0Ip0ud+6c4+Mif2Z+V4OXxfqz+4gSzJd2R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zoFxtmVq3QDjb0iw39YtOZWc0FQgghhHwbLpv6mZUQQgghj4eZlRBCCHlKmFkJIYSQp4SZlRBCCHlKmFkJIYSQp4SZlRBCCHk6vn79L63oX5vxQ4dtAAAAAElFTkSuQmCC" alt=" " />
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 5007
using namespace std;
int n, m, k, pre[N], dis[N][], ls[N];
int mi[], tot;
struct edge
{
int to, next, pre;
}e[N * ];
int list[N * ][]; void add(int x, int y, int z)
{
e[++tot].to = y;
e[tot].next = ls[x];
e[tot].pre = z;
ls[x] = tot;
} void init()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n; i++)
{
int x;
pre[i] = ;
for (int j = ; j <= k; j++)
{
scanf("%d", &x);
pre[i] += x * mi[j];
}
} for (int i = ; i <= m; i++)
{
int x, y, z;
scanf("%d%d", &x, &y);
int p = ;
for (int j = ; j <= k; j++)
scanf("%d", &z), p += mi[j] * z;
add(x, y, p);
}
} void pre_work()
{
mi[] = ;
for (int i = ; i <= ; i++)
mi[i] = mi[i - ] * ; } void work()
{
memset(dis, 0x7f7f7f7f, sizeof(dis));
dis[][pre[]] = ;
list[][] = ;
list[][] = pre[];
int head = , tail = ;
while (head < tail)
{
head++;
int now = list[head][];
int p = list[head][];
for (int i = ls[now]; i; i = e[i].next)
{
if ((p | e[i].pre) != p) continue;
int net = p | pre[e[i].to];
if (dis[e[i].to][net] == 0x7f7f7f7f)
{
dis[e[i].to][net] = dis[now][p] + ;
list[++tail][] = e[i].to;
list[tail][] = net;
}
}
}
int ans = 0x7f7f7f7f;
for (int i = ; i <= mi[k + ] - ; i++)
ans = min(ans, dis[n][i]);
if (ans != 0x7f7f7f7f) printf("%d", ans);
else printf("No Solution");
} int main()
{
//freopen("room.in", "r", stdin);
//freopen("room.out", "w", stdout);
pre_work();
init();
work();
}
JZOJ 5459. 【NOIP2017提高A组冲刺11.7】密室的更多相关文章
- [JZOJ 5465] [NOIP2017提高A组冲刺11.9] 道路重建 解题报告 (e-dcc+树的直径)
题目链接: http://172.16.0.132/senior/#main/show/5465 题目: 小X所居住的X国共有n个城市,有m条无向道路将其连接.作为一个统一的国家,X 城的任意两个城市 ...
- JZOJ 5462. 【NOIP2017提高A组冲刺11.8】好文章
5462. [NOIP2017提高A组冲刺11.8]好文章 (File IO): input:article.in output:article.out Time Limits: 1000 ms M ...
- JZOJ 5456. 【NOIP2017提高A组冲刺11.6】奇怪的队列
5456. [NOIP2017提高A组冲刺11.6]奇怪的队列 (File IO): input:queue.in output:queue.out Time Limits: 1000 ms Mem ...
- JZOJ 5455. 【NOIP2017提高A组冲刺11.6】拆网线
455. [NOIP2017提高A组冲刺11.6]拆网线 (File IO): input:tree.in output:tree.out Time Limits: 1000 ms Memory L ...
- JZOJ 5461. 【NOIP2017提高A组冲刺11.8】购物
5461. [NOIP2017提高A组冲刺11.8]购物 (File IO): input:shopping.in output:shopping.out Time Limits: 1000 ms ...
- 5458. 【NOIP2017提高A组冲刺11.7】质数
5458. [NOIP2017提高A组冲刺11.7]质数 (File IO): input:prime.in output:prime.out Time Limits: 1000 ms Memory ...
- [JZOJ5455]【NOIP2017提高A组冲刺11.6】拆网线
Description 企鹅国的网吧们之间由网线互相连接,形成一棵树的结构.现在由于冬天到了,供暖部门缺少燃料,于是他们决定去拆一些网线来做燃料.但是现在有K只企鹅要上网和别人联机游戏,所以他们需要把 ...
- 【NOIP2017提高A组冲刺11.8】好文章
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> us ...
- 【NOIP2017提高A组冲刺11.6】拆网线
和syq大兄弟吐槽题目不小心yy出了正解.. 最优的选法就是选两个两个相互独立的,欸这不就是最大匹配吗?那多的企鹅就新加一条边呗?不够的就除以2上取整呗? 欸?AC了? 树也是一个二分图,最大匹配=最 ...
随机推荐
- Spring和springMVC父子容器的关系
部分转载自:https://www.cnblogs.com/ljdblog/p/7461854.html springMVC容器和Spring容器 为什么一定要在web.xml中配置spring的li ...
- PHP 中获取文件名及路径
1. basename("/mnt/img/image01.jpg")函数:得到文件名;输出结果为:image01.jpg. 使用 basename($uriString) 我们可 ...
- struts2的执行流程
在浏览器端输入相应的访问地址>>>>把请求发送给tomact>>>>tomact判断应该交给那个webApplication>>>&g ...
- HTML5 参数传递
页面显示效果,如下图: 主页面代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- IUserStore------Implements Diagram
- GitLab-CE-8.9.4 (OpenLogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: gitlab-8.9.4 bug tracking collaboration commercial development devops git ...
- nginx 升级为最新版 nginx -1.12.0
标签:nginx 公司目前使用的nginx版本比较低(nginx-1.0.12),请网络安全公司做了一下“远程安全评估”,发现有下列漏洞: nginx URI处理安全限制绕过漏洞(CVE-2013-4 ...
- linux 命令——53 route(转)
Linux系统的route 命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需 要一台连接两个网络的路由器 ...
- spa 小程序的研发随笔 (2) --- 预编译
因为是连续写的2篇随笔,废话不多说.直接进入正题. 选择预编译的工具时,笔者采用了gulp.虽然,如今市面上大多采用的多为webpack,使用gulp也是有自己的缘由的. webpack的最主要特点是 ...
- 【BZOJ2733】[HNOI2012] 永无乡(启发式合并Splay)
点此看题面 大致题意: 给你一张图,其中每个点有一个权值,有两种操作:在两点之间连一条边,询问一个点所在联通块第\(k\)小的权值. 平衡树 看到第\(k\)小,应该不难想到平衡树. 为了练习\(Sp ...