"bzoj1449/bzoj2895" [JSOI2009] Team yield/team budget fee flow

Source: Internet
Author: User

Title Description

Input

Output

An integer that represents the minimum value of the sum of all the teams in the league.

Sample input

3 3
1 0 2 1
1 1 10 1
0 1 3 3
0 S
2 3
3 1

Sample output

43

Exercises

Cost flow

Because there is a win a lose, more difficult to calculate. We can assume that they all lose and then arrange the winning situation.

Set fi for I also to play the number of games, then the initial yield of ∑ci*wi^2+di* (LI+FI) ^2.

S-> per game with a capacity of 1 and a cost of 0.

The two teams for each match, with a capacity of 1, cost 0.

Because the cost is changed to include the square, so we need to split the side to do.

The group I team to the T-Fi bar, the capacity is 1, the J-side indicates win J Field more than win j-1 field more income, so the cost should be ci* (wi+j) ^2+di* (wi+fi-j) ^2-ci* (li+j-1) ^2-di* (li+j+1) ^2.

For convenience, the FI is added directly to Li.

Then run the minimum cost maximum flow, plus the previous initial gain is the answer.

#include <cstdio> #include <cstring> #include <queue> #define N 10010#define M 3500000using namespace  Std;queue<int> Q;int W[n], l[n], c[n], d[n], x[n], y[n], F[n];int head[n], to[m], val[m], cost[m], next[m] , CNT = 1, S, T, Dis[n], from[n], pre[n];void Add (int x, int y, int v, int c) {to[++cnt] = y, val[cnt] = V, cost [CNT] = c, next[cnt] = head[x], head[x] = cnt;to[++cnt] = x, val[cnt] = 0, cost[cnt] =-C, next[cnt] = Head[y], head [Y] = cnt;} BOOL SPFA () {int x, I;memset (from,-1, sizeof (from)), memset (DIS, 0x3f, sizeof (DIS));d is[s] = 0, Q.push (s), and while (!q.em Pty ()) {x = Q.front (), Q.pop (); for (i = head[x]; i; i = Next[i]) if (Val[i] && dis[to[i]] > Dis[x] + cost[i]) dis [To[i]] = dis[x] + cost[i], from[to[i] [= x, pre[to[i]] = i, Q.push (To[i]);} return ~from[t];} int Mincost () {int i, k, ans = 0;while (SPFA ()) {k = 0x7fffffff;for (i = t; I! = s; i = from[i]) k = min (k, val[pre[i]); Ans + = k * Dis[t];for (i = t; I! = s; i = fRom[i]) val[pre[i] [= k, val[pre[i] ^ 1] + = k; return ans;} int main () {int n, m, I, j, ans = 0;scanf ("%d%d", &n, &m), s = 0, t = m + n + 1;for (i = 1; I <= n; i + +) scanf ("%d%d%d%d", &w[i], &l[i], &c[i], &d[i]); for (i = 1; I <= m; i + +) scanf ("%d%d", &x [i], &y[i]), F[x[i]] + +, F[y[i]] + +, L[x[i]] + +, L[y[i]] + +; for (i = 1; I <= n; i + +) ans + = c[i] * W[i] *  W[i] + d[i] * l[i] * L[I];FOR (i = 1; I <= m; i + +) Add (s, I, 1, 0), add (I, x[i] + m, 1, 0), add (I, y[i] + M  , 1, 0); for (i = 1; I <= n; i + +) for (j = 1; J <= F[i]; j + +) Add (i + M, T, 1, C[i] * (2 * w[i) + 2 * j-1) -D[i] * (2 * l[i]-2 * j + 1));p rintf ("%d\n", ans + mincost ()); return 0;}

"bzoj1449/bzoj2895" [JSOI2009] Team yield/team budget fee 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.