一开始在https://www.cnblogs.com/lokiii/p/10770919.html基础上连(i,j,b[i][j])建了个极丑的图T掉了……把dinic换成isap勉强能卡过

首先因为有正负收益所以考虑最小割,先ans=Σb,然后考虑负收益

把割完后和s相邻的视为不选,反之视为选,选的话要付出代价a,所以连(s,i,a[i]);然后考虑如果ij一个选一个不选(这里是单向的),需要Eij的代价,所以连(i,j,E[i][j]);然后是如果一个点不选的话那么所有Eij都不会被加,所以连边(i,t,ΣE[i][j])

跑最小割即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<queue>
  4. #include<cstring>
  5. using namespace std;
  6. const int N=1005;
  7. int n,s,t,h[N],cnt=1,le[N];
  8. long long b[N][N],ans;
  9. struct qwe
  10. {
  11. int ne,to;
  12. long long va;
  13. }e[N*N*4];
  14. int read()
  15. {
  16. int r=0,f=1;
  17. char p=getchar();
  18. while(p>'9'||p<'0')
  19. {
  20. if(p=='-')
  21. f=-1;
  22. p=getchar();
  23. }
  24. while(p>='0'&&p<='9')
  25. {
  26. r=r*10+p-48;
  27. p=getchar();
  28. }
  29. return r*f;
  30. }
  31. void add(int u,int v,long long w)
  32. {
  33. cnt++;
  34. e[cnt].ne=h[u];
  35. e[cnt].to=v;
  36. e[cnt].va=w;
  37. h[u]=cnt;
  38. }
  39. void ins(int u,int v,long long w)
  40. {
  41. add(u,v,w);
  42. add(v,u,0);
  43. }
  44. bool bfs()
  45. {
  46. memset(le,0,sizeof(le));
  47. queue<int>q;
  48. le[s]=1;
  49. q.push(s);
  50. while(!q.empty())
  51. {
  52. int u=q.front();
  53. q.pop();
  54. for(int i=h[u];i;i=e[i].ne)
  55. if(e[i].va>0&&!le[e[i].to])
  56. {
  57. le[e[i].to]=le[u]+1;
  58. q.push(e[i].to);
  59. }
  60. }
  61. return le[t];
  62. }
  63. long long dfs(int u,long long f)
  64. {
  65. if(u==t||!f)
  66. return f;
  67. long long us=0;
  68. for(int i=h[u];i&&us<f;i=e[i].ne)
  69. if(e[i].va>0&&le[e[i].to]==le[u]+1)
  70. {
  71. long long t=dfs(e[i].to,min(e[i].va,f-us));
  72. e[i].va-=t;
  73. e[i^1].va+=t;
  74. us+=t;
  75. }
  76. if(!us)
  77. le[u]=0;
  78. return us;
  79. }
  80. long long dinic()
  81. {
  82. long long r=0;
  83. while(bfs())
  84. r+=dfs(s,1e11);
  85. return r;
  86. }
  87. int main()
  88. {
  89. n=read();
  90. s=0,t=n+1;
  91. for(int i=1;i<=n;i++)
  92. ins(s,i,read());
  93. for(int i=1;i<=n;i++)
  94. {
  95. long long sm=0;
  96. for(int j=1;j<=n;j++)
  97. {
  98. b[i][j]=read();
  99. if(b[i][j])
  100. sm+=b[i][j],ans+=b[i][j],ins(i,j,b[i][j]<<1);
  101. }
  102. ins(i,t,sm);
  103. }
  104. printf("%lld\n",ans-dinic());
  105. return 0;
  106. }

bzoj 2039: [2009国家集训队]employ人员雇佣【最小割】的更多相关文章

  1. BZOJ 2039: [2009国家集训队]employ人员雇佣

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1369  Solved: 667[Submit ...

  2. 【BZOJ2039】[2009国家集训队]employ人员雇佣 最小割

    [BZOJ2039][2009国家集训队]employ人员雇佣 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作有一个贡献 ...

  3. BZOJ 2039 [2009国家集训队]employ人员雇佣 网络流

    链接 BZOJ 2039 题解 这题建图好神,自己瞎搞了半天,最后不得不求教了企鹅学长的博客,,,,发现建图太神了!! s向每个人连sum(e[i][x]) 的边,每个人向T连a[i]的边.两两人之间 ...

  4. BZOJ 2039 / Luogu P1791 [2009国家集训队]employ人员雇佣 (最小割)

    题面 BZOJ传送门 Luogu传送门 分析 考虑如何最小割建图,因为这仍然是二元关系,我们可以通过解方程来确定怎么建图,具体参考论文 <<浅析一类最小割问题 湖南师大附中 彭天翼> ...

  5. bzoj 2039 [2009国家集训队]employ人员雇佣——二元关系

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2039 用最小割看.对于一组关系 i , j ,如果都选,收益 2*Ei,j,可以看作0,作为 ...

  6. 【BZOJ 2039】 2039: [2009国家集训队]employ人员雇佣 (最小割)

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1511  Solved: 728 Descri ...

  7. 【BZOJ2039】【2009国家集训队】人员雇佣 [最小割]

    人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 作为一个富有经营头脑的富翁,小L决 ...

  8. 2039: [2009国家集训队]employ人员雇佣

    任意门 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作有一个贡献指数,(我们用Ei,j表示i经理对j经理的了解程度),即 ...

  9. BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割

    BZOJ_2039_[2009国家集训队]employ人员雇佣_ 最小割 Description 作为一个富有经营头脑的富翁,小L决定从本国最优秀的经理中雇佣一些来经营自己的公司.这些经理相互之间合作 ...

随机推荐

  1. Ahead-of-time compilation

    https://en.wikipedia.org/wiki/Ahead-of-time_compilation

  2. left outer join preserving unmatched rows from the first table

    https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj18922.html INNER JOIN operation Specifies a join ...

  3. react遇到的各种坑

    标签里用到<label for>的,for 要写成htmlFor 标签里的class要写成className 组件首字母一定要大写 单标签最后一定要闭合 如果html里要空格转义, 注意不 ...

  4. mac10.10 打造Python多版本虚拟环境

    一.简介 1.在操作系统mac10.10(yosemite)中搭建Python多版本虚拟环境: 2.多版本虚拟环境包含三个含义: 在一个操作系统中安装多个版本的Python,不同版本可以随意切换,例如 ...

  5. leetcode 750. Number Of Corner Rectangles

    Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectang ...

  6. 并不对劲的bzoj5322:loj2543:p4561:[JXOI2018]排序问题

    题目大意 \(T\)(\(T\leq10^5\))组询问 每次给出\(n,m,l,r\),和\(n\)个数\(a_1,a_2,...,a_n\),要找出\(m\)个可重复的在区间\([l,r]\)的数 ...

  7. CodeForces - 597C:Subsequences (主席树+DP)

    For the given sequence with n different elements find the number of increasing subsequences with k + ...

  8. POJ1201 Intervals (差分约束)

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  9. js some和filter用法和区别

    some方法 array1.some(callbackfn[, thisArg]) 对数组array1中的每个元素调用回调函数callbackfn,当回调函数返回true或者遍历完所有数组后,some ...

  10. 查看mysql连接情况,以及连接超时时间设置

    查看连接: show processlist;   只展示100个连接 show full processlist;    展示所有连接 查看超时时间: show variables like  '% ...