uva_658 It's not a Bug, it's a Feature! Dijkstra(优先队列)
来源:互联网 发布:新东方考研单词软件 编辑:程序博客网 时间:2024/06/03 01:40
#include <cstdio>#include <algorithm>#include <queue> using namespace std;#define N 21#define M 101 const int inf = 500000000; int pre[2][M], next[2][M]; int t[M];int d[1<<N]; typedef pair<int, int> pii; void dijkstra(int n, int m){ for (int i = 0; i < (1 << n); i++)d[i] = inf; priority_queue<pii, vector<pii>, greater<pii> > q; d[(1 << n) - 1] = 0; q.push(make_pair(0, (1 << n) - 1)); while (!q.empty()) { pii u = q.top();q.pop(); int x = u.second; if (u.first != d[x])continue; for (int i = 0; i < m ; i++)if (((x | pre[0][i]) == x) && (x&pre[1][i])== x) { int v = x | next[0][i]; v &= next[1][i]; if (d[x] + t[i] < d[v]) { d[v] = d[x] + t[i]; q.push(make_pair(d[v], v)); } } } } int ca = 1; int main(){ int n, m; char b1[N], b2[N]; while (scanf("%d %d", &n, &m) != EOF && (m + n)) { for (int i = 0; i < m; i++) { scanf("%d %s %s", t + i, b1, b2); pre[0][i] = pre[1][i] = next[0][i] = next[1][i] = 0; for (int j = 0; j < n; j++) { if (b1[j] == '+')pre[0][i] |= (1 << j); if (b1[j] != '-')pre[1][i] |= (1 << j); if (b2[j] == '+')next[0][i] |= (1 << j); if (b2[j] != '-')next[1][i] |= (1 << j); } } dijkstra(n, m); printf("Product %d\n", ca++); if (d[0] == inf)puts("Bugs cannot be fixed."); else printf("Fastest sequence takes %d seconds.\n", d[0]); puts(""); } return 0;}
- uva_658 It's not a Bug, it's a Feature! Dijkstra(优先队列)
- uva 658 - It's not a Bug, it's a Feature!(优先队列Dijkstra)
- UVA - 658 It’s not a Bug, it’s a Feature!(优先队列Dijkstra)
- UVA 658 - It's not a Bug, it's a Feature!(dijkstra+优先队列)
- UVa 658 It's not a Bug, it's a Feature! 位运算技巧+dijkstra优先队列优化
- uva658 - It's not a Bug, it's a Feature! 状态压缩+隐式图搜索+优先队列的dijkstra
- hdu 1818 It's not a Bug, It's a Feature!(位运算+bfs优先队列)
- 658 - It's not a Bug, it's a Feature!-----------优先队列和spfa----做了很长时间!!!(好题!)
- hdu 1818 hdu 1818 It's not a Bug, It's a Feature!(位运算+bfs优先队列)
- UVa 658 - It's not a Bug, it's a Feature!(Dijkstra算法)
- hdu1818 It's not a Bug, It's a Feature!(隐式图最短路径Dijkstra)
- 658 - It's not a Bug, it's a Feature! (Dijkstra算法)
- UVa 658It's not a Bug, it's a Feature! -- 最短路dijkstra
- UVA658[It's not a Bug, it's a Feature!] BellmanFord || Dijkstra 求最短路
- 658 - It's not a Bug, it's a Feature!
- It's not a BUG, it's a FEATURE!
- poj1483 It's not a Bug, It's a Feature!
- UVa658 - It's not a Bug, it's a Feature!
- 【100题】求1+2+……+n的和-----方法二
- uva_10397 Connect the Campus
- 做好系统的整体把控——综合管理系统开发
- 段选择器 段描述符 段描述符表 线性地址形成
- 所谓的“密钥比率”这东西
- uva_658 It's not a Bug, it's a Feature! Dijkstra(优先队列)
- 使用opencv比较两个图片的相似性
- 串口通信参数设置(1)
- 异或解题:Find the Lost Sock
- 博客搬家了
- JAVA修饰符
- vector连续删除元素
- UVA 10986 Sending email DIJSKRA(稀疏图)
- Shortest Path