Simplicity and Network flow

Source: Internet
Author: User

Simplicity Template:

Requires B > 0, xi > 0.

1 //Simple Sex2 //n+1 * m+1 Matrix3 //1~n to constrain <= right value4 //n+1 is the target maximum value5 //Dual Direct transpose6 Const intMAXN =1100, MAXM =11000;7 Const DoubleEPS = 1e-7, INF =1e20;8 intDCMP (DoubleA) {returnFabs (a) <eps?0:a<0?-1:1; }9 intN, M;Ten DoubleA[MAXM][MAXN]; One voidPivotintLinte) { A      for(inti =1; I <= N; i++)if(I! = l&&dcmp (A[i][e])) { -          for(intj =1; J <= M; J + +) -             if(J! = e) a[i][j]-= a[i][e]/a[l][e]*A[l][j]; theA[i][e]/=-A[l][e]; -     } -      for(inti =1; I <= m; i++)if(I! = e) a[l][i]/= a[l][e]; A[l][e] =1/A[l][e]; - } +  - Doublesimplex () { +     Doublemn; A     inte, L; at      while(1){ -          for(e=1; e<m;e++)if(DCMP (a[n][e]) >0) Break; -         if(E = = m)return-A[n][m]; -MN =INF; -          for(intI=1; i<n;i++)if(DCMP (a[i][e]) >0&& mn > A[i][m]/a[i][e]) mn = a[l=i][m]/A[i][e]; -         if(MN = = INF)returnINF; in pivot (l, e); -     } to}
View Code

bzoj1061

Test instructions: There are n days, the first day I need AI volunteers, there is a class m volunteers, each type of volunteer work time for [l,r], cost CI, for the minimum cost

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMAXN =1100, MAXM =11000;5 Const DoubleEPS = 1e-7, INF =1e20;6 intDCMP (DoubleA) {returnFabs (a) <eps?0:a<0?-1:1; }7 intN, M;8 DoubleA[MAXM][MAXN];9 voidPivotintLinte) {Ten      for(inti =1; I <= N; i++)if(I! = l&&dcmp (A[i][e])) { One          for(intj =1; J <= M; J + +) A             if(J! = e) a[i][j]-= a[i][e]/a[l][e]*A[l][j]; -A[i][e]/=-A[l][e]; -     } the      for(inti =1; I <= m; i++)if(I! = e) a[l][i]/= a[l][e]; A[l][e] =1/A[l][e]; - } -  - Doublesimplex () { +     Doublemn; -     inte, L; +      while(1){ A          for(e=1; e<m;e++)if(DCMP (a[n][e]) >0) Break; at         if(E = = m)return-A[n][m]; -MN =INF; -          for(intI=1; i<n;i++)if(DCMP (a[i][e]) >0&& mn > A[i][m]/a[i][e]) mn = a[l=i][m]/A[i][e]; -         if(MN = = INF)returnINF; - pivot (l, e); -     } in } -  to intMain () { +scanf"%d%d", &n, &m); -     //duality the      for(inti =1; I <= N; i++) *scanf"%LF", &a[m+1][i]); $      for(inti =1, L, R, V; I <= m; i++) {Panax Notoginsengscanf"%d%d%d", &l, &r, &v); -          for(intj = l; J <= R; J + +) A[i][j] =1; thea[i][n+1] =v; +     } An++, m++; the swap (n, m); +printf"%d", (int) (simplex () +0.50)); -     return 0; $}
View Code

Simplicity and Network flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.