Bzoj 3112: [Zjoi2013] Defensive front [simplex method]

Source: Internet
Author: User

Title Description

The front line can be regarded as a sequence of length n, now it is necessary to build towers on this sequence to defend the enemy soldiers, to build a tower with CI in the Sequence No. I position, and a position can be built any number of towers, cost cumulative calculation. There are m zones [L1, R1], [L2, R2], ..., [Lm, Rm], at least di tower in the range of section I. Minimum cost.

Input/output format

Input format:

The first behavior is two numbers n, M.

On the next line, there are n numbers, which describe the C array.

Next m line, three numbers per line Li,ri,di, describes an interval.

Output format:

Contains only one row, a number, and a minimum cost.

Input and Output Sample input example # #:
5 31 5 6 3 42 3 11 5 43 5 2
Sample # # of output:
11
Description

"Sample description"

Location 1 built 2 towers, location 3 built a tower, location 4 built a tower. Cost 1*2+6+3=11.

"Data Size"

For 20% of data, n≤20,m≤20.

For 50% of the data (including the last part of the data), Di is all 1.

For 70% of the data (including the previous part of the data), n≤100,m≤1000.

For 100% of the data, N≤1000,m≤10000,1≤li≤ri≤n, the rest of the data are ≤10000.

It's like 08 volunteer recruiting.

Set X as the vector of whether the tower is built for each location, 1 build 0 not built

Minimize CX

Satisfy constraint I constraint is x[l[i]]+x[l[i]+1]+...+x[r[i]]>=d[i]

namely Ax>=d

A[I][J] for 1 means that the first constraint j in [L[i],r[i]], can contribute to the

After the duality, it becomes

Maximize DX

Meet constrained at X<=c

Note that this time is n constraints, m variables

////main.cpp//zjoi2013 Defensive Front////Created by Candy on 2016/12/16.//copyright©2016 year Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intm=10005, n=1005, inf=1e9;Const Doubleeps=1e-6; inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intn,m;Doublea[n][m],b[n],c[m],v;voidPivotintLinte) {B[l]/=A[l][e];  for(intI=1; i<=n;i++)if(i!=e) a[l][i]/=A[l][e]; A[l][e]=A[l][e];  for(intI=1; i<=m;i++)if(I!=l&&fabs (a[i][e]) >0) {B[i]-=a[i][e]*B[l];  for(intj=1; j<=n;j++)if(j!=e) a[i][j]-=a[i][e]*A[l][j]; A[i][e]=-a[i][e]*A[l][e]; } v+=c[e]*B[l];  for(intj=1; j<=n;j++)if(j!=e) c[j]-=c[e]*A[l][j]; C[e]=-c[e]*a[l][e];}voidsimplex () { while(true){        intE=0, l=0; Doublemn=INF;  for(e=1; e<=n;e++)if(c[e]>eps) Break; if(e==n+1)return;  for(intI=1; i<=m;i++)            if(A[i][e]>eps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i; if(Mn==inf)return;//unboundedpivot (l,e); }}intMainintargcConst Char*argv[]) {N=read (); m=read ();  for(intI=1; i<=n;i++) scanf ("%LF",&B[i]);  for(intI=1; i<=m;i++){        intL=read (), r=read ();  for(intj=l;j<=r;j++) a[j][i]=1.0; scanf ("%LF",&C[i]);    } swap (M,n);    Simplex (); printf ("%d",(int) (v+0.5)); return 0;}

Bzoj 3112: [Zjoi2013] Defensive front [simplex method]

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.