Bzoj 2245: [SDOI2011] work schedule (cost flow)

Source: Internet
Author: User

2245: [SDOI2011] Work schedule time Limit: Sec Memory Limit: MB
Submit: 1446 Solved: 692
[Submit] [Status] [Discuss] Description

your company has received a batch of orders. Orders require your company to provide n products, products are numbered 1~n, of which category I products need Ci pieces. The company has a staff of m , employees are numbered 1~m employees can be manufactured by different types of products. A product must be manufactured entirely by an employee and not be made by one of the employees, and then transferred to another employee for further manufacturing.

we use a0and the1composed ofM*nThe MatrixAto describe which products each employee can manufacture. The rows and columns of the matrix are numbered separately1~mand the1~n,Ai,jto be1represents an employeeIability to manufacture productsJ, for0represents an employeeICannot manufacture productsJ.

If the company assigns too much work to an employee, the employee becomes unhappy. We use anger values to describe an employee's mood state. The higher the anger value, the more upset the employee is, and the lower the anger value, indicating the happier the employee is in his mood. The employee's anger value has a functional relationship with the number of products he is scheduled to manufacture, and the functional relationships between employees are different, given their ability to withstand them.

for EmployeesI, the function between his rage value and the product quantity is asi+1fragment function of the segment. When he made the first1~ti,1Product , each product will increase the value of his angerwi,1, when he made the firstti,1+1~ti,2Product , each product will increase the value of his angerwi,2... For the convenience of the description, setti,0=0,ti,si+1= +∞, then when he made the firstti,j-1+1~ti,jProduct , each product will increase the value of his angerwi,j,1≤J≤si+1 .

your task is to work out a distribution plan for the product, so that the order conditions are met, and all employees ' anger values are minimized. Since we do not want to use special Judge, and in order to give the player more time to study the other two topics, you only need to output the sum of the minimum rage values.

Input

The first line consists of two positive integers m and the N , representing the number of employees and the number of products;

The second line contains N a positive integer, section I a positive integer of Ci ;

following m row per row N an integer description matrix A ;

< Span style= "font-family: Arial" > below m section, section i section describes employees i si si a positive integer, where section j A positive integer is ti,j si=0 So the input will not leave blank lines (that is, this part consists of only two lines). The third line contains the si+1 j A positive integer is wi,j

Output

Outputs only an integer that represents the sum of the smallest rage values.

Sample Input
2 3

2 2 2

1 1 0

0 0 1

1

2

1 10

1

2

1 6

Sample Output24

HINT

Source

First round Day2

[Submit] [Status] [Discuss]

Maximum flow of minimum cost.

Product capacity is c[i] at source point, cost 0

Product-to-production capacity of the product is INF and costs 0

Person-to-sink function has how many segments to even how many edges, capacity of t[i]-t[i-1], the cost is w[i]

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < queue> #include <cmath> #define M 2000000#define N 3000#define LL long long#define inf 1000000000using namespace St D;int M,n,tot;int next[m],point[n],remain[m],v[m],last[m],can[m],total; LL c[m],mincost,dis[m];void Add (int x,int y,int z,ll k) {tot++; next[tot]=point[x]; point[x]=tot; v[tot]=y; c[tot]=k; r    Emain[tot]=z; tot++; Next[tot]=point[y]; Point[y]=tot; V[tot]=x; C[tot]=-k; remain[tot]=0;}    int addflow (int s,int t) {int now=t; int ans=inf;        while (now!=s) {ans=min (Ans,remain[last[now]]);    NOW=V[LAST[NOW]^1];    } now=t;        while (now!=s) {Remain[last[now]]-=ans;        Remain[last[now]^1]+=ans;    NOW=V[LAST[NOW]^1]; } return ans;    BOOL SPFA (int s,int t) {for (int i=s;i<=t;i++) Dis[i]=inf;    memset (Can,0,sizeof (Can)); dis[s]=0;    Can[s]=1; Queue<int> p;    P.push (s); while (!p.empty ()) {int nOw=p.front ();        P.pop (); for (int i=point[now];i!=-1;i=next[i]) if (Dis[v[i]]>dis[now]+c[i]&&remain[i]) {di            S[v[i]]=dis[now]+c[i];            Last[v[i]]=i;                if (!can[v[i]]) {can[v[i]]=1;             P.push (V[i]);    }} can[now]=0;    } if (Dis[t]==inf) return false; int Maxflow=addflow (S,T);    Total+=maxflow;     mincost+= (long Long) dis[t]*maxflow; return true;} void solve (int s,int t) {while (SPFA (s,t));}    int main () {scanf ("%d%d", &m,&n);    Tot=-1;    memset (point,-1,sizeof (point));    memset (Next,-1,sizeof (next));        for (int i=1;i<=n;i++) {int x; scanf ("%d", &x);      Add (1,i+1,x,0);        } for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) {int x; scanf ("%d", &x);      if (x) Add (j+1,n+1+i,inf,0);    } int num=n+m+2;        for (int i=1;i<=m;i++) {int x; scanf ("%d", &x); int t[10],w[10];        t[0]=0;        for (int j=1;j<=x;j++) scanf ("%d", &t[j]);        T[x+1]=inf;            for (int j=1;j<=x+1;j++) {LL y; scanf ("%lld", &y);         Add (n+1+i,num,t[j]-t[j-1],y);    }} solve (1,num); printf ("%lld\n", Mincost);}


Bzoj 2245: [SDOI2011] work schedule (cost 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.