tjut 3488
来源:互联网 发布:js确认密码 编辑:程序博客网 时间:2024/06/10 03:06
#include <cstdlib>#include <cstring>#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int N, M;const int INF = 0x3f3f3f3f;int w[205][205];int lx[205], ly[205];int sx[205], sy[205];int match[205], slack[205];int path(int u) { sx[u] = 1; for (int i = 1; i <= N; ++i) { if (sy[i]) continue; int t = lx[u] + ly[i] - w[u][i]; if (!t) { sy[i] = 1; if (!match[i] || path(match[i])) { match[i] = u; return true; } } else { slack[i] = min(slack[i], t); } } return false;}void KM() { memset(match, 0, sizeof (match)); memset(lx, 0x80, sizeof (lx)); memset(ly, 0, sizeof (ly)); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { lx[i] = max(lx[i], w[i][j]); } } for (int i = 1; i <= N; ++i) { memset(slack, 0x3f, sizeof (slack)); while (1) { memset(sx, 0, sizeof (sx)); memset(sy, 0, sizeof (sy)); if (path(i)) break; int d = INF; for (int j = 1; j <= N; ++j) { if (!sy[j]) d = min(d, slack[j]); } for (int j = 1; j <= N; ++j) { if (sx[j]) lx[j] -= d; if (sy[j]) ly[j] += d; else slack[j] -= d; } } } int ret = 0; for (int i = 1; i <= N; ++i) { ret += w[match[i]][i]; } printf("%d\n", -ret);}int main() { int T, x, y, ct; scanf("%d", &T); while (T--) { scanf("%d %d", &N, &M); memset(w, 0x80, sizeof (w)); for (int i = 1; i <= M; ++i) { scanf("%d %d %d", &x, &y, &ct); w[x][y] = max(w[x][y], -ct); } KM(); } return 0; }
0 0
- tjut 3488
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- 关于hadoop找不到class的问题
- javascript函数的四种调用模式及参数this的取值
- 在ActionBar / ToolBar 中添加 overflow menu的方法
- 反射的原理
- 读《三体》差点污了我的三观
- tjut 3488
- Android 开关机动画 BootAnimation/ShutdownAnimation 解析
- java将字节转换成十六进制输出
- Leetcode39:Combination Sum
- Cocos2d-x Lua学习笔记
- 创建Android新工程时,丢失MainActivity.java文件,丢失R.java文件,values/values-v11/values-v14 styles.xml文件出错
- 提高情商的八种方法
- Android03--Android之UI布局01FrameLayout
- textView取消回车换行