1139: [POI2009]Wie

https://www.lydsy.com/JudgeOnline/problem.php?id=1139

分析:

  Dijkstra。状压最短路,dis[i][j]表示到第i个点,状态为j的最短路。

  或者 分层最短路可以做。

代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
const int M = ; int dis[][], head[N], to[M<<], nxt[M<<], sta[M<<], len[M<<], S[N], Enum, n;
bool vis[][]; struct Heap{
int u, dis, st;
Heap() {}
Heap(int a,int b,int c) {u = a, dis = b, st = c;}
bool operator < (const Heap &A) const {
return dis > A.dis;
}
};
priority_queue < Heap > q; void add_edge(int u,int v,int w,int s) {
++Enum; to[Enum] = v; len[Enum] = w; sta[Enum] = s; nxt[Enum] = head[u]; head[u] = Enum;
++Enum; to[Enum] = u; len[Enum] = w; sta[Enum] = s; nxt[Enum] = head[v]; head[v] = Enum;
} int Dijkstra() {
memset(dis, 0x3f, sizeof(dis));
dis[][] = ;
q.push(Heap(, , ));
while (!q.empty()) {
int d = q.top().dis, u = q.top().u, s = q.top().st; q.pop();
if (u == n) return d;
if (vis[u][s]) continue;
vis[u][s] = true;
s |= S[u];
for (int i=head[u]; i; i=nxt[i]) {
int v= to[i];
if ((sta[i] | s) != s) continue;
if (dis[v][s] > d + len[i]) {
dis[v][s] = d + len[i];
q.push(Heap(v, dis[v][s], s));
}
}
}
return -;
} int main () { n = read(); int m = read(), p = read(), k = read();
for (int w,cnt,t,st,i=; i<=k; ++i) {
w = read(), cnt = read();
for (int j=; j<=cnt; ++j) {
t = read();
S[w] |= ( << (t - ));
}
}
for (int i=; i<=m; ++i) {
int u = read(), v = read(), w = read(), cnt = read(), st = , t;
for (int j=; j<=cnt; ++j) {
t = read();
st |= ( << (t - ));
}
add_edge(u, v, w, st);
}
printf("%d",Dijkstra());
return ;
}

1139: [POI2009]Wie的更多相关文章

  1. [POI2009]Wie

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

  2. bzoj1139:[POI2009]Wie

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

  3. bzoj AC倒序

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

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

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

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

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

  6. BZOJ 1142: [POI2009]Tab

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

  7. URAL 1139 City Blocks(数论)

    The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...

  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 ...

随机推荐

  1. 推荐一个Chrome扩展应用,能够自动去除CSDN广告

    作为一个程序员,每天编程遇到问题时,少不了前往国内著名的CSDN网站上查信息,看是否有同行遇到类似问题.很多时候根据遇到问题的错误消息进行搜索,结果都是一篇篇CSDN博客.这些博客打开后都会显示很多广 ...

  2. 使flex-direction: column的子元素height: 100%生效的办法

    在flex-direction: column子元素里直接使用height:100%,height并不会被设置成100% <!DOCTYPE html> <html lang=&qu ...

  3. 『看球笔记』20140208利物浦VS阿森纳,十字重剑与蜜蜂飞舞

      红圈位置42%对58%的控球率,是不是觉得比分很不符?我们卖个关子,最后再说这个.   十字重剑     第一次任意球防守,俩后卫盯俩后卫,负责斯科特尔的是科斯切尔尼,而默特萨克盯图雷.     ...

  4. Ubuntu不支持rpm安装软件解决方法

    Ubuntu不支持rpm安装软件解决方法 以前经常使用的是RedHat Linux,习惯使用rpm方法安装软件.最近发现Ubuntu系统居然不支持rpm方法安装软件,提示信息如下: root@root ...

  5. [19/03/12-星期二] 数组_遍历(for-each)&复制&java.util.Arrays类

    一.遍历 for-each即增强for循环,是JDK1.5新增加的功能,专门用于读取数组或集合中所有的元素,即对数组进行遍历. //数组遍历 for-each public class Test_03 ...

  6. express框架开发笔记

    1.express项目修改不重启 $ supervisor node bin/www 让supervisor监听模板文件的改动 $ supervisor --extensions html,css,j ...

  7. ASP.NET整体运行机制+asp.net请求管道+页面生命周期+MVC整体运行机制原理图

    在网上找的,个人感觉很好的

  8. input按钮选择功能

    <p> <input type="checkbox" class="ischecked" id="is_pinkage" ...

  9. static函数

    C语言中使用静态函数的好处:      静态函数会被自动分配在一个一直使用的存储区,直到退出应用程序实例,避免了调用函数时压栈出栈,速度快很多.       关键字“static”,译成中文就是“静态 ...

  10. Git相关内容

    先聊一点关于gitlab的内容和github的内容 Gitlab和GitHub,都是我们可以存放代码库的地方.不过Gitlab可以免费的存储私人代码,GitHub需要花钱才能够存储私人代码库,不过我想 ...