Bzoj 3550 ONTAK2010 Vacation simplex

Source: Internet
Author: User

The main topic: given a length of 3n interval, the need to select some number, and any length of n interval of the maximum number of k, the maximum number of selected numbers

Simplex directly engage in

Note that a number can only be selected once, so add xi<=1 to this binding condition

Do not understand 3n and k<=10 is why ...

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define EPS 1e-7#define INF 1e10using namespace Std;int n,m,k;namespace linear_programming{double A[1210][ 610],b[1210],c[610],v;void Pivot (int l,int e) {int i,j;b[l]/=a[l][e];for (i=1;i<=n;i++) if (i!=e) a[l][i]/=a[l][e]; A[l][e]=1/a[l][e];for (i=1;i<=m;i++) if (I!=l&&fabs (A[i][e]) >eps) {b[i]-=a[i][e]*b[l];for (j=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 (i=1;i<=n;i++) if (i!=e) c[i]-=c[e]*a[l][i];c[e]=-c[e]*a[l][e];} Double Simplex () {int I,l,e;while (1) {for (i=1;i<=n;i++) if (c[i]>eps) break;if ((e=i) ==n+1) return v;double temp= Inf;for (i=1;i<=m;i++) if (a[i][e]>eps && b[i]/a[i][e]<temp) temp=b[i]/a[i][e],l=i;if (Temp==INF) return INF; Pivot (l,e);}}} int main () {using namespace Linear_programming;int i,j;cin>>n>>k;for (i=1;i<=n*3;i++) scanf ("%lf", &c[i]); for (i=1;i+n-1<=n*3;i++) {b[++m]=k;for (j=i;j<=i+n-1;j++) a[m][j]=1;} for (i=1;i<=n*3;i++) {b[++m]=1; A[m][i]=1;} N*=3;double Ans=simplex (); Cout<<int (ans+0.5) <<endl;return 0;}


Bzoj 3550 ONTAK2010 Vacation simplex

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.