题意
描述不清。。。
Sol
网络流24题里面怎么会有状压dp??
真是狗血,不过还是简单吧。
直接用$f[sta]$表示当前状态为$sta$时的最小花费
转移的时候枚举一下哪一个补丁可以搞这个状态
但是这玩意儿有后效性,可以用SPFA消去
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; const int MAXN = 101, INF = 1e9 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = 1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N, M; int tim[MAXN], dis[2097153], B1[MAXN], B2[MAXN], F1[MAXN], F2[MAXN], vis[2097153]; int SPFA() { queue<int> q; q.push((1 << N) - 1); dis[(1 << N) - 1] = 0; while(!q.empty()) { int sta = q.front(); q.pop(); vis[sta] = 0; for(int i = 1; i <= M; i++) { int now = sta; if(((sta & B1[i]) == B1[i]) && ((sta & B2[i]) == 0)) { now = now & (~F1[i]); now = now | F2[i]; if(dis[now] > dis[sta] + tim[i]) { dis[now] = dis[sta] + tim[i]; if(!vis[now]) q.push(now); } } } } return dis[0] < INF ? dis[0] : 0; } int main() { N = read(); M = read(); memset(dis, 0x3f, sizeof(dis)); for(int i = 1; i <= M; i++) { char s1[21], s2[21]; scanf("%d %s %s", &tim[i], s1, s2); for(int j = 0; j < N; j++) if(s1[j] == '+') B1[i] |= 1 << j; else if(s1[j] == '-') B2[i] |= 1 << j; for(int j = 0; j < N; j++) if(s2[j] == '-') F1[i] |= 1 << j; else if(s2[j] == '+') F2[i] |= 1 << j; } printf("%d", SPFA()); return 0; } /* 3 3 1 000 00- 1 00- 0-+ 2 0-- -++ */