[BZOJ3550] [ONTAK2010] Vacation (simplex) __

Source: Internet
Author: User
Topic Description

Transfer Door solving

Simplex nude question
One thing to keep in mind is to limit the number of choices per number <=1 code

#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <
Cmath> using namespace std;
#define N 1005 const double eps=1e-9;
const double INF=1E18;
int n,m,k;

Double A[n][n],b[n],c[n],ans;
    void pivot (int l,int e) {b[l]/=a[l][e];
    for (int i=1;i<=n;++i) if (i!=e) a[l][i]/=a[l][e];
    A[l][e]=1.0/a[l][e];
            for (int i=1;i<=m;++i) if (I!=l&&fabs (a[i][e)) >eps) {b[i]-=b[l]*a[i][e];
            for (int j=1;j<=n;++j) if (j!=e) a[i][j]-=a[l][j]*a[i][e];
        A[i][e]=-a[i][e]*a[l][e];
    } Ans+=b[l]*c[e];
    for (int i=1;i<=n;++i) if (i!=e) c[i]-=c[e]*a[l][i];
C[e]=-c[e]*a[l][e];
        } void Simplex () {while (1) {int E;
        for (E=1;e<=n;++e) if (c[e]>eps) break;
        if (e==n+1) break;
        Double Min=inf,t;int L;
    for (int i=1;i<=m;++i)        if (a[i][e]>eps&& (T=b[i]/a[i][e]) <min) {min=t;
            L=i;
    } pivot (l,e);
    int main () {scanf ("%d%d", &n,&k);
    for (int i=1;i<=3*n;++i) scanf ("%lf", &c[i));
        for (int i=1;i<=2*n+1;++i) {b[i]=k+0.0;
    for (int j=i;j<=i+n-1;++j) a[i][j]=1.0;
    for (int i=2*n+2;i<=5*n+1;++i) b[i]=1,a[i][i-2*n-1]=1;
    M=5*n+1;n*=3;simplex ();
    printf ("%.0lf\n", ans);
return 0; }

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.