Bzoj 3996 [Tjoi 2015] linear algebra problem Solving report

Source: Internet
Author: User

First, we can get:

$ $D = \sum_{i=1}^{n}\sum_{j=1}^{n}a_i\times a_j\times b_{i,j}-\sum_{i=1}^{n}a_i\times c_i$$

So is it the equivalent of the question:

There are $n $ items, you can choose some items to come out, if you chose $i at the same time, j$ two items then there is $b _{i,j}$ benefits, but every item has a price $c _i$, to seek the maximum benefit.

This is the classic minimal cut model:

    • The Edge $S \to Dot (i,j) $ with a flow rate of $b _{i,j}$.
    • The Edge $Dot (i,j) \to i$ and the $Dot (i,j) \to j$ with a traffic of $\infty$.
    • Edge $i \to t$, flow rate is $c _i$

Set the minimum cut to $x $, then the answer is:

$$\SUM_{I=1}^{N}\SUM_{J=1}^{N}B_{I,J}-x$$

Although there are a lot of points, but can still run fast. (*^_^*)

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 #defineN 250000 + 500 + 59 #defineM 2500000 + 5Ten #defineINF 0x7fffffff One  A intN, S, T, cnt, tot =1; - intHead[n], q[n], dfn[n]; - LL ans; the  - structEdge - { -     intNext, node, flow; + }h[m]; -  +InlinevoidAddedge (intUintVintFL) A { ath[++ Tot].next = Head[u], head[u] =tot; -H[tot].node = V, H[tot].flow =FL; -h[++ Tot].next = Head[v], head[v] =tot; -H[tot].node = u, H[tot].flow =0; - } -  inInlineBOOLBFS () - { to      for(inti = S; I <= T; i + +) +Dfn[i] =0; -     intL =1, r =1; theq[1] = S, dfn[s] =1; *      while(L <=R) $     {Panax Notoginseng         intz = q[l + +]; -          for(inti = head[z]; I i =h[i].next) the         { +             intd = h[i].node, p =H[i].flow; A             if(!p | | DFN[D])Continue ; theDFN[D] = Dfn[z] +1; +q[++ R] =D; -             if(d = = T)return 1; $         } $     } -     return 0; - } the  -InlineintDinic (intZintinflow)Wuyi { the     if(z = = T)returninflow; -     intRET =inflow, flow; Wu      for(inti = head[z]; I i =h[i].next) -     { About         intd = h[i].node, p =H[i].flow; $         if(Dfn[d]! = Dfn[z] +1|| !P)Continue ; -Flow =Dinic (d, Min (P, ret)); -RET-=flow; -H[i].flow-= flow, H[i ^1].flow + =flow; A         if(!ret)returninflow; +     } the     if(ret = = inflow) DFN[Z] =-1; -     returnInflow-ret; $ } the  the intMain () the { the #ifndef Online_judge -Freopen ("3996.in","R", stdin); inFreopen ("3996.out","W", stdout); the     #endif the      Aboutscanf"%d", &n); theS =0, T = n + N * n +1, cnt =N; the      for(inti =1; I <= N; i + +) the          for(intj =1, W; J <= N; J + +) +         { -scanf"%d", &W); theAddedge (S, + +)CNT, W);Bayi Addedge (CNT, I, INF); the Addedge (CNT, J, INF); theAns + =W; -         } -      for(inti =1, W; I <= N; i + +) the     { thescanf"%d", &W); the Addedge (i, T, W); the     } -      while(BFS ()) theAns-=dinic (S, INF); theprintf"%lld\n", ans); the     94 #ifndef Online_judge the fclose (stdin); the fclose (stdout); the     #endif98     return 0; About}
3996_gromah

Bzoj 3996 [Tjoi 2015] linear algebra problem Solving report

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.