Bzoj 3550 [ontak2010]vacation linear programming

Source: Internet
Author: User
link : Method: Linear programming parsing: This is a fairly simple linear programming of simplicity. First we set Xi x_i to indicate whether the number I is selected. it is clear x1+x2+...+xn<=k x_1+x_2+...+x_n x2+x3...+xn+1<=k x_2+x_3...+x_{n+1} . .. x2n+1+x2n+2+...+x3n<=k x_{2n+1}+x_{2n+2}+...+x_{3n} Second 0<=xi<=1 0 and we want to maximize ∑3ni=1ci∗xi \sum_{i=1}^{3n}c_i*x_i The above equation is obviously a standard linear programming. The simple solution is OK. How complex is it to solve these things? If you look at the code, or you understand the whole process. It is obviously O (nm) when the limit is eliminated. But when we enumerate the variables with coefficients greater than 0 in the target function, the worst enumeration is O (n). so it's the worst thing to reach O (n^2*m), and it seems a bit close to the network stream. so, which one is faster? Maybe you can try it someday. Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 610 #defi
NE INF 0x7f7f7f7f using namespace std;
Double a[n<<1][n<<1];
int N,k,tot;
    int check () {for (int i=1;i<=3*n;i++) if (a[0][i]>0) return i;
return 0;
        } void Simplex () {while (int t=check ()) {double limit=inf;
        int choseline;
            for (int i=1;i<=tot;i++) {if (a[i][t]<=0) continue;
        else if (a[i][0]/a[i][t]<limit) {limit=a[i][0]/a[i][t];choseline=i}
        } if (Limit==inf) {a[0][0]=inf;break;}
        Double di=a[choseline][t];
            for (int i=0;i<=3*n;i++) {if (i==t) A[choseline][i]/=di;
        A[choseline][i]/=di; for (int i=0;i<=tot;i++) {if (i==choseline| |
            a[i][t]==0) continue;
            if (i==0) a[i][0]+=a[choseline][0]*a[i][t];
            else a[i][0]-=a[choseline][0]*a[i][t]; Double L=A[I][T];
                for (int j=1;j<=3*n;j++) {if (j==t) a[i][j]=-l*a[choseline][j];
            else A[i][j]-=l*a[choseline][j];
    int main () {scanf ("%d%d", &n,&k);
        for (int i=1;i<=2*n+1;i++) {int to=i+n-1;
        tot++;
        for (int j=i;j<=to;j++) a[tot][j]=1;
    A[tot][0]=k;
        for (int i=1;i<=3*n;i++) {tot++;
    A[tot][i]=1,a[tot][0]=1;
    for (int i=1;i<=3*n;i++) scanf ("%lf", &a[0][i));
    Simplex ();
printf ("%.0lf\n", a[0][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.