水题随便A
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int dist[2000000];
int js[100];
struct lyd
{
int s1,s2,c1,c2,time;
}a[200];
queue<int> Q;
int main()
{
int n,m;
cin >> n >> m;
js[1] = 1;
for(int i = 2;i <= 30;i ++)
js[i] = (js[i-1] << 1);
memset(dist,63,sizeof(dist));
for(int i = 1;i <= m;i ++)
{
cin >> a[i].time;
char ch[100];
scanf("%s",ch);
for(int k = 0;k < n;k ++)
{
if(ch[k] == '+')
a[i].s1 += js[k+1];
if(ch[k] == '-')
a[i].s2 += js[k+1];
}
scanf("%s",ch);
for(int k = 0;k < n;k ++)
{
if(ch[k] == '+')
a[i].c1 += js[k+1];
if(ch[k] == '-')
a[i].c2 += js[k+1];
}
}
dist[js[n+1]-1] = 0;
Q.push(js[n+1]-1);
while(!Q.empty())
{
int p = Q.front();
Q.pop();
for(int i = 1;i <= m;i ++)
{
if((p&a[i].s1) == a[i].s1 && ((~p)&a[i].s2) == a[i].s2)
{
int k = (p|a[i].c1)^(p&a[i].c2);
if(dist[k] > dist[p] + a[i].time)
{
dist[k] = dist[p] + a[i].time;
Q.push(k);
}
}
}
}
if(dist[0] != 1061109567)
cout << dist[0] << endl;
else
cout << 0 << endl;
return 0;
}