UVa658 It's not a Bug, it's a Feature!
来源:互联网 发布:多邻国提醒连接网络 编辑:程序博客网 时间:2024/05/20 06:28
It is a curious fact that consumers buying a new software product
generally do not expect the software to be bug-free. Can you imagine
buying a car whose steering wheel only turns to the right? Or a
CD-player that plays only CDs with country music on them? Probably
not. But for software systems it seems to be acceptable if they do not
perform as they should do. In fact, many software companies have
adopted the habit of sending out patches to fix bugs every few weeks
after a new product is released (and even charging money for the
patches). Tinyware Inc. is one of those companies. After releasing a
new word processing software this summer, they have been producing
patches ever since. Only this weekend they have realized a big problem
with the patches they released. While all patches fix some bugs, they
often rely on other bugs to be present to be installed. This happens
because to fix one bug, the patches exploit the special behavior of
the program due to another bug. More formally, the situation looks
like this. Tinyware has found a total of n bugs B
= f b 1 ; b 2 ; : : : ; b n g in their software. And they have released m patches p 1 ; p 2 ; : : : ; p m . To apply patch p i to the
software, the bugs B
+ i B have to be present in the software, and the bugs B
二进制压缩保存状态和补丁,然后用类似堆优化dijkstra/A*+判重【我也不知道算啥】的方法扩展。
#include<cstdio>#include<algorithm>#include<cstring>#include<queue>using namespace std;int n,m,w[110],dis[5000010];unsigned int a[110],b[110],c[110],d[110];void init(){ int i,j; char s[110]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); for (i=1;i<=m;i++) { scanf("%d",&w[i]); scanf("%s",s); for (j=0;j<n;j++) if (s[j]!='0') { a[i]^=1<<j; if (s[j]=='+') b[i]^=1<<j; } scanf("%s",s); for (j=0;j<n;j++) if (s[j]!='0') { if (s[j]=='+') d[i]^=1<<j; } else c[i]^=1<<j; }}int solve(){ int j; unsigned int u,v,x; pair<int,int> tem; priority_queue<pair<int,int> >q; q.push(make_pair(0,(1<<n)-1)); memset(dis,0x3f,sizeof(dis)); dis[(1<<n)-1]=0; while (!q.empty()) { tem=q.top(); u=tem.second; x=-tem.first; q.pop(); if (u==0) return x; for (j=1;j<=m;j++) if (((u&a[j])^b[j])==0) { v=(u&c[j])|d[j]; if (x+w[j]<dis[v]) { dis[v]=x+w[j]; q.push(make_pair(-dis[v],v)); } } } return -1;}int main(){ int K=0,x; while (scanf("%d%d",&n,&m)&&n) { printf("Product %d\n",++K); init(); if ((x=solve())!=-1) printf("Fastest sequence takes %d seconds.\n",x); else printf("Bugs cannot be fixed.\n"); printf("\n"); }}
- UVa658 - It's not a Bug, it's a Feature!
- UVA658 It's not a Bug, it's a Feature!
- UVa658 It's not a Bug, it's a Feature!
- [二进制位运算状态 隐式图搜索]UVa658 - It's not a Bug, it's a Feature!
- UVA658-It's not a Bug, it's a Feature!-最短路
- UVA658[It's not a Bug, it's a Feature!] BellmanFord || Dijkstra 求最短路
- uva658 - It's not a Bug, it's a Feature! 状态压缩+隐式图搜索+优先队列的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!
- It's not a Bug, it's a Feature! UVA
- It's not a Bug, it's a Feature! UVA
- It's not a Bug, it's a Feature! UVA
- It's not a Bug, it's a Feature! UVA
- 【UVa658】【SPFA】【状态压缩】It's not a Bug,it's a Featurel.
- UVA 658 - It's not a Bug, it's a Feature!
- uva_658 It's not a Bug, it's a Feature! Dijkstra(优先队列)
- Uva 658 - It's not a Bug, it's a Feature!//最短路
- 51nod 1087 1 10 100 1000
- 背包问题
- 51nod 1088 最长回文子串
- interrupt、interrupted 、isInterrupted 区别
- 51nod 1089 最长回文子串 V2(Manacher算法)
- UVa658 It's not a Bug, it's a Feature!
- 时间复杂度和空间复杂度
- 51nod 1090 3个数和为0
- hdu oj从1000-1001-1002
- JMM主内存与工作内存交互
- 常用开发工具的API文档大全
- NOIP2012提高组 同余方程
- Linux Shell 通配符、元字符、转义符使用实例介绍
- 用pandas分析百万电影数据