隐式的图搜索,存不下边,所以只有枚举转移就行了,因为bug的存在状态可以用二进制表示,转移的时候判断合法可以用位运算优化,

二进制pre[i][0]表示可以出现的bug,那么u&pre[i][0] == u就表示u是可以出现的bug集合的子集,

pre[i][1]表示必须出现的bug,那么u|pre[i][i] != u表示把必须出现的bug添加到u中,u中bug增加表面bug不全在u中,这是不合法的。

正权最短路就dijkstra,用spfa以前某题狂T有阴影。被输出格式坑得不要不要的,如果是if(kas) putchar('\n');就会WA...

#include<bits/stdc++.h>
using namespace std; const int maxm = ;
const int maxn = ; int pre[maxm][],nxt[maxm][];
int cost[maxm];
int n,m; int dist[<<maxn]; typedef pair<int,int> Node;
#define fi first
#define se second //bitset<20> temp;
#define bug(u)\
temp = u; cout<<#u<<'='<<temp<<endl;
#define cer(x)\
cout<<"dist="<<x<<endl; const int INF = 0x3f3f3f3f; void dijkstra()
{
priority_queue<Node,vector<Node>,greater<Node> > q;
memset(dist,0x3f,sizeof(int)*(<<n));
q.push(Node(,(<<n)-));
dist[(<<n)-] = ;
while(q.size()){
Node x = q.top(); q.pop();
if(x.se == ) { printf("Fastest sequence takes %d seconds.\n",dist[]); return; }
if(x.fi != dist[x.se]) continue;
int u = x.se;
for(int i = ; i < m; i++){
if( (pre[i][]&u) == u && (pre[i][]|u) == u){
int v = (u&nxt[i][])|nxt[i][];
if(dist[v] > dist[u]+cost[i]){
dist[v] = dist[u] + cost[i];
q.push(Node(dist[v],v));
}
}
}
}
puts("Bugs cannot be fixed.");
} int main()
{
//freopen("in.txt","r",stdin);
int kas = ;
char s1[maxn+],s2[maxn+];
while(scanf("%d%d",&n,&m),n){
for(int i = ; i < m ; i++){
scanf("%d%s%s",cost+i,s1,s2);
nxt[i][] = nxt[i][] = pre[i][] = pre[i][] = ;
for(int j = ; j < n; j++){
if(s1[j] == '+') pre[i][] |= <<j;
if(s1[j] != '-') pre[i][] |= <<j;
if(s2[j] == '+') nxt[i][] |= <<j;
if(s2[j] != '-') nxt[i][] |= <<j;
}
}
printf("Product %d\n",++kas);
dijkstra();
putchar('\n');
}
return ;
}

UVA - 658 It's not a Bug, it's a Feature! (隐式图的最短路,位运算)的更多相关文章

  1. UVa 658 - It's not a Bug, it's a Feature!(Dijkstra + 隐式图搜索)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA 658 It's not a Bug, it's a Feature! (最短路,经典)

    题意:有n个bug,有m个补丁,每个补丁有一定的要求(比如某个bug必须存在,某个必须不存在,某些无所谓等等),打完出来后bug还可能变多了呢.但是打补丁是需要时间的,每个补丁耗时不同,那么问题来了: ...

  3. UVA 658 It's not a Bug, it's a Feature!

    这个题目巧妙之处在于用二进制的每个位1,0分别表示bug的有无,以及实施补丁对相应bug的要求以及实施后的对bug的影响. 软件bug的状态:1表示相应bug仍然存在,0表示已经修复.这样可以将软件的 ...

  4. UVa 658 It's not a Bug, it's a Feature! (状态压缩+Dijstra)

    题意:首先给出n和m,表示有n个bug和m个补丁.一开始存在n个bug,用1表示一个bug存在0表示不存在,所以一开始就是n个1,我们的目的是要消除所有的bug, 所以目标状态就是n个0.对于每个补丁 ...

  5. 【UVA】658 - It&#39;s not a Bug, it&#39;s a Feature!(隐式图 + 位运算)

    这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...

  6. UVA 658 状态压缩+隐式图+优先队列dijstla

    不可多得的好题目啊,我看了别人题解才做出来的,这种题目一看就会做的实在是大神啊,而且我看别人博客都看了好久才明白...还是对状态压缩不是很熟练,理解几个位运算用了好久时间.有些题目自己看着别人的题解做 ...

  7. It&#39;s not a Bug, It&#39;s a Feature! (poj 1482 最短路SPFA+隐式图+位运算)

    Language: Default It's not a Bug, It's a Feature! Time Limit: 5000MS   Memory Limit: 30000K Total Su ...

  8. 倒水问题UVA 10603——隐式图&&Dijkstra

    题目 给你三个容量分别为 $a,b,c$ 的杯子,最初只有第3个杯子装满了水,其他两个杯子为空.最少需要到多少水才能让一个某个杯子中的水有 $d$ 升呢?如果无法做到恰好 $d$ 升,就让某个杯子里的 ...

  9. UVa 10603 Fill (BFS && 经典模拟倒水 && 隐式图)

    题意 : 有装满水的6升的杯子.空的3升杯子和1升杯子,3个杯子中都没有刻度.不使用道具情况下,是否可量出4升水呢? 你的任务是解决一般性的问题:设3个杯子的容量分别为a, b, c,最初只有第3个杯 ...

随机推荐

  1. TimeUtils(没试过)

    package util; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseExc ...

  2. visual editor ve1.5下载

    eclipse官网的ve下载不了,下面这个能下 http://sourceforge.net/projects/visualeditor/files/latest/download

  3. 甩掉 ashx/asmx,使用jQuery.ajaxWebService请求WebMethod,Ajax处理更加简练

    在WebForm下 开发ajax程序,需要借助于一般处理程序(*.ashx)或web服务(*.asmx),并且每一个ajax请求,都要建一个这样的文件,如此一来,如果在一个项目中ajax程序多了,势必 ...

  4. Unity5自动命名Assetbundle并打包

    http://www.shihuanjue.com/?p=57 using UnityEngine; using System.Collections; using UnityEditor; usin ...

  5. 2016 Noip提高组

    2557. [NOIP2016]天天爱跑步 ★★☆   输入文件:runninga.in   输出文件:runninga.out   简单对比时间限制:2 s   内存限制:512 MB [题目描述] ...

  6. Metabolic and gut microbial characterization of obesity-prone mice under high-fat diet (文献分享一组-赵容丽)

    题目:高脂饮食下易肥胖小鼠的代谢和肠道微生物特性研究 Metabolic and gut microbial characterization of obesity-prone mice under ...

  7. IT兄弟连 JavaWeb教程 JSP经典案例

    案例需求:定义一个javaBean叫XdlUser,有四个字段int id.String name.int age.double salary.写一个jsp页面,在页面中构建一个列表对象,里面存放几个 ...

  8. ionic4+angular7+cordova开发入门

    前言 ionic是一个垮平台开发框架,可通过web技术开发出多平台的应用.但只建议开发简单应用.复杂的应用需要用到许多cordova插件,而cordova插件的更新或者移动平台的更新很可能导致插件的不 ...

  9. 新手安装 hadoop、hive和hbase 笔记

    系统是ubuntu 12.04 , hadoop版本是1.2.1 , hive版本是0.12 , hbase版本我忘记了,不好意思首先是配置好hostnamevi /etc/hosts写入你要配置的i ...

  10. JS实现 类的 1.判断 2.添加 3.删除 4切换

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...