标签:存在 scan def namespace none pop max cost air
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int maxn = 3e6+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct graph
{
int head[maxn],nxt[maxn<<1],to[maxn<<1],w[maxn<<1],sz;
void init(){memset(head,-1,sizeof(head));}
graph(){init();}
void push(int a,int b,int c){nxt[sz]=head[a],to[sz]=b,w[sz]=c,head[a]=sz++;}
int& operator[](const int a){return to[a];}
}g;
char s[22],t[22];
struct edge
{
int need,noneed,creat,del,c;
}a[105];
int d[1100005];
bool vis[1100005];
int main()
{
#ifndef ONLINE_JUDGE
freopen("simple.in", "r", stdin);
freopen("simple.out", "w", stdout);
#endif
int n,m;
scanf("%d%d",&n,&m);
int mx = 1<<n;
for(int i = 1,c;i <= m;++i){
scanf("%d%s%s",&a[i].c,s,t);
for(int j = 0;j < n;++j){
if(s[j]==‘+‘)a[i].need|=1<<j;
else if(s[j]==‘-‘)a[i].noneed|=1<<j;
if(t[j]==‘+‘)a[i].creat|=1<<j;
else if(t[j]==‘-‘)a[i].del|=1<<j;
}
}
memset(d,0x3f,sizeof(d));
d[mx-1]=0;
priority_queue<p>q;
q.push(make_pair(0,mx-1));
while(!q.empty()){
p now = q.top();
q.pop();
int cost = -now.first;
int u = now.second;
if(cost>d[u])continue;
vis[u]=1;
for(int i = 1;i <= m;++i){
if(((a[i].need&u)==a[i].need)&&((a[i].noneed&u)==0)){
int tmp = u|a[i].del;
tmp^=a[i].del;
tmp|=a[i].creat;
if(!vis[tmp]){
if(d[tmp]>cost+a[i].c){
d[tmp]=cost+a[i].c;
q.push(make_pair(-d[tmp],tmp));
}
}
}
}
}
if(!vis[0]){
printf("0\n");
}
else printf("%d\n",d[0]);
return 0;
}
标签:存在 scan def namespace none pop max cost air
原文地址:https://www.cnblogs.com/aaddvvaanntteezz/p/13032726.html