https://www.luogu.org/problem/show?pid=3489

题目描述

Byteasar has become a hexer - a conqueror of monsters.

Currently he is to return to his hometown Byteburg. The way home, alas, leads through a land full of beasts. Fortunately the habitants, forced to fight the monsters for centuries, have mastered the art of blacksmithery - they are now capable of making special swords that are very efficient against the beasts.

The land Byteasar wanders through is quite vast: many towns lie there, and many roads connect them.

These roads do not cross outside the towns (mostly because some of them are underground passages).

Byteasar has gathered all practical information about the land (all hexers like to know these things).

He knows what kind of monsters he may come across each of the roads and how much time he needs to walk it down.

He also knows in which villages there are blacksmiths and against what kinds of monsters the swords that they make work.

Byteasar wants to get back to Byteburg as soon as possible.

As a hexer he is quite ashamed that he does not know the best route, and that he has no sword on him at the moment.

Help him find the shortest path to Byteburg such that whenever he could meet some king of monster, previously he would have a chance to get an appropriate sword to fight the beast.

You need not worry about the number or weight of the swords - every hexer is as strong as an ox, so he can carry (virtually) unlimited number of equipment, swords in particular.

大陆上有n个村庄,m条双向道路,p种怪物,k个铁匠,每个铁匠会居住在一个村庄里,你到了那个村庄后可以让他给你打造剑,每个铁匠打造的剑都可以对付一些特定种类的怪物,每条道路上都可能出现一些特定种类的怪物,每条道路都有一个通过所需要的时间,现在要从1走到n,初始的时候你没有剑,要求在经过一条道路的时候,对于任意一种可能出现在这条道路上的的怪物,你都有已经有至少一把剑可以对付他,求从1走到n的最短时间(打造剑不需要时间)

输入输出格式

输入格式:

The first line of the standard input holds four integers: n,m,p,kn,m,p,k (1\le n\le 200,0\le m\le 3000,1\le p\le 13,0\le k\le n1≤n≤200,0≤m≤3000,1≤p≤13,0≤k≤n),separated by single spaces, that denote respectively:

the number of towns, the number of roads connecting them,the number of different kinds of monsters and the number of blacksmiths.

The towns are numbered from 11 to nn in such a way that nn is Byteburg's number and 11 is the number of the village which Byteasar starts in. The monster kinds are numbered from 11 to pp.

In the following kk lines the profiles of successive blacksmiths are given,one per line. The (i+1)(i+1)-st line holds the integers w_i,q_i,r_{i,1}<r_{i,2}<...<r_{i,q_i}w​i​​,q​i​​,r​i,1​​<r​i,2​​<...<r​i,q​i​​​​(1\le w_i\le n,1\le q_i\le p,1\le r_{i,j}\le p1≤w​i​​≤n,1≤q​i​​≤p,1≤r​i,j​​≤p),separated by single spaces, that denote respectively: the number of town in which the blacksmith lives, the number of different kinds of monsters against which his swords are efficient, and the kinds of monsters themselves (in increasing order). Note that a town may have more than one blacksmith.

Then mm lines with roads' descriptions follow.The (k+i+1)(k+i+1)-th line holds the integersv_i,w_i,t_i,s_i,u_{i,1}<u_{i,2}<...<u_{i,s_i}v​i​​,w​i​​,t​i​​,s​i​​,u​i,1​​<u​i,2​​<...<u​i,s​i​​​​(1\le v_i<w_i\le n,1\le t_i\le 500,0\le s_i\le p,1\le u_{i,j}\le p1≤v​i​​<w​i​​≤n,1≤t​i​​≤500,0≤s​i​​≤p,1≤u​i,j​​≤p)separated by single spaces, that denote respectively: the towns that the road connects, the time needed to walk down the road (same in both directions), the number of different kinds of monsters that may appear on that road, and finally the kinds of monsters themselves (in increasing order). No two roads connect the same pair of towns.

输出格式:

Your programme is to print out one integer to the standard output - the minimum summary time required to reach Byteburg.

Should reaching Byteburg be impossible, the number should be -1−1.

输入输出样例

输入样例#1:

6 7 4 2
2 1 2
3 2 1 3
1 2 2 0
2 3 9 0
1 4 2 1 2
2 5 3 0
4 5 5 2 2 3
4 6 18 0
5 6 3 2 1 2
输出样例#1:

24

状压最短路
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
int sword[];
int dis[][];
bool v[][];
int front[],to[],nxt[],sta[],val[],tot;
struct node
{
int now,state;
}cr,nt;
queue<node>q;
void add(int u,int v,int w,int s)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; sta[tot]=s; val[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; sta[tot]=s; val[tot]=w;
}
int main()
{
int n,m,p,k;
scanf("%d%d%d%d",&n,&m,&p,&k);
int live,sum,x;
while(k--)
{
scanf("%d%d",&live,&sum);
while(sum--)
{
scanf("%d",&x);
sword[live]|=<<x-;
}
}
int u,t,w,state;
while(m--)
{
scanf("%d%d%d%d",&u,&t,&w,&sum);
state=;
while(sum--)
{
scanf("%d",&x);
state|=<<x-;
}
add(u,t,w,state);
}
memset(dis,,sizeof(dis));
cr.now=;
cr.state=sword[];
dis[][sword[]]=;
v[][sword[]]=true;
q.push(cr);
while(!q.empty())
{
cr=q.front();
q.pop();
v[cr.now][cr.state]=false;
for(int i=front[cr.now];i;i=nxt[i])
if((sta[i]&cr.state)==sta[i] && dis[to[i]][sword[to[i]]|cr.state]>dis[cr.now][cr.state]+val[i])
{
dis[to[i]][sword[to[i]]|cr.state]=dis[cr.now][cr.state]+val[i];
if(!v[to[i]][sword[to[i]]|cr.state])
{
v[to[i]][sword[to[i]]|cr.state]=true;
nt.now=to[i]; nt.state=sword[to[i]]|cr.state;
q.push(nt);
}
}
}
tot=<<p;
int ans=dis[n][];
for(int i=;i<tot;i++) ans=min(ans,dis[n][i]);
if(ans>) ans=-;
printf("%d",ans);
return ;
}

[POI2009]WIE-Hexer的更多相关文章

  1. 1139: [POI2009]Wie

    1139: [POI2009]Wie https://www.lydsy.com/JudgeOnline/problem.php?id=1139 分析: Dijkstra.状压最短路,dis[i][j ...

  2. [POI2009]Wie

    题目 BZOJ 虽然是解压题但也学到了简洁的码风 做法 \(dijkstra\)跑动规 My complete code #include<bits/stdc++.h> #include& ...

  3. bzoj1139:[POI2009]Wie

    传送门 状压dp,最短路 spfa似乎特别慢 代码: #include<cstdio> #include<iostream> #include<algorithm> ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. BZOJ 1115: [POI2009]石子游戏Kam

    1115: [POI2009]石子游戏Kam Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 883  Solved: 545[Submit][Stat ...

  6. BZOJ 4384: [POI2015]Trzy wieże

    4384: [POI2015]Trzy wieże Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 217  Solved: 61[Submit][St ...

  7. BZOJ 1142: [POI2009]Tab

    1142: [POI2009]Tab Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 213  Solved: 80[Submit][Status][D ...

  8. 【BZOJ】【1115】【POI2009】石子游戏KAM

    博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...

  9. bzoj 1133: [POI2009]Kon dp

    1133: [POI2009]Kon Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 242  Solved: 81[Submit][Status][D ...

  10. bzoj 1138: [POI2009]Baj 最短回文路 dp优化

    1138: [POI2009]Baj 最短回文路 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 161  Solved: 48[Submit][Sta ...

随机推荐

  1. Thunder团队第六周 - Scrum会议3

    Scrum会议3 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...

  2. 20145214 《Java程序设计》第6周学习总结

    20145214 <Java程序设计>第6周学习总结 教材学习内容总结 串流设计 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象. 输入串流代表对象为java. ...

  3. lintcode-187-加油站

    187-加油站 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油gas[i],并且从第_i_个加油站前往第_i_+1个加油站需要消耗汽油cost[i]. 你有一辆油箱容量无限大的汽车,现在要从 ...

  4. lintcode-39-恢复旋转排序数组

    39-恢复旋转排序数组 给定一个旋转排序数组,在原地恢复其排序. 说明 什么是旋转数组? 比如,原始数组为[1,2,3,4], 则其旋转数组可以是[1,2,3,4], [2,3,4,1], [3,4, ...

  5. LintCode-372.在O(1)时间复杂度删除链表节点

    在O(1)时间复杂度删除链表节点 给定一个单链表中的一个等待被删除的节点(非表头或表尾).请在在O(1)时间复杂度删除该链表节点. 样例 给定 1->2->3->4,和节点 3,删除 ...

  6. 【week2】四人小组项目(WBS、NABCD)

    项目选题:东北师范大学论坛 小组名称:nice! 项目组长:李权 组员:于淼 刘芳芳 杨柳 本周任务:要求给出需求概述.功能列表.痛点或亮点.NABCD及WBS模型在此项目中的应用. 作为东北师范大学 ...

  7. VUE01指令

    一.下载Vue2.0的两个版本: 官方网站:http://vuejs.org/ 开发版本:包含完整的警告和调试模式 生产版本:删除了警告,进行了压缩 二.项目结构搭建 这个部分要视频中有详细讲解. 三 ...

  8. PHPcms企业黄页中,会员注册之后提示经营模式不得少于1个字符 的解决办法

    后台--模块- 黄页模块 ---  企业库 --- 字段 ---   经营模式 ---  字符长度取值范围 1  改为  0. 

  9. mysql学习之数据备份与恢复

    该文使用mysql5.5 centos6.5 64位(本人使用rpm安装mysql,数据库的安装目录默认) 一.数据备份注意事项 读锁问题:数据库(或者某个表)一旦进行读锁操作则影响数据库的写操作所以 ...

  10. canvas drawImage 不显示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...