jzoj6367. [2019.9.25] NOIP2019 simulation plant (factory)

Here Insert Picture Description
Here Insert Picture Description

Competitions

⑧ say, because the game T1 engage in a self-closing.
No hasty brain like a little pressure, roll thick.

answer

In fact, this problem is really very simple.
First of all, the title will be particularly special given interval.
So there must be several intervals does not contain any interval. (bananaIntersection is not)
we carry out these intervals, into a collection of a.
While other sections must contain at least a section of a collection.
These intervals into another set b.

Then we can find some small nature -
1, we found that can put a collection of random intervals into several lines, just to ensure that working time> 0 can be.
2, secondly, each b set intervals or inserted into the assembly it contains a range of, not contribute, either alone into a new collection, produced their own expense.

So we can do a separately.
First we set \ (f _ {[i] [j]} \) represents the i-th before the current collection interval into a maximum value of the j-th pipeline.
Transfer apparently. \ (O (n ^ 3) \)

Then the rest is free to join a collection of b.
We removed some of the largest direct b range, you can.

Standard process

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
const int maxn=210;

int n,m,ga,gb,ans;
int x[maxn],y[maxn],ax[maxn],ay[maxn],bx[maxn],by[maxn];
int f[maxn][maxn],sum[maxn];
bool bz[maxn];

void qsortb(int l,int r)
{
    int i=l;int j=r;
    int m=by[(i+j)/2]-bx[(i+j)/2]+1;
    while (i<=j)
    {
        while (by[i]-bx[i]+1>m) i++;
        while (by[j]-bx[j]+1<m) j--;
        if (i<=j)
        {
            swap(bx[i],bx[j]);
            swap(by[i],by[j]);
            i++;j--;
        }
    }
    if (l<j) qsortb(l,j);
    if (r>i) qsortb(i,r); 
}

void qsorta(int l,int r)
{
    int i=l;int j=r;
    int m=ax[(i+j)/2];
    int m1=ay[(i+j)/2];
    while (i<=j)
    {
        while ((ax[i]<m) || (ax[i]==m && ay[i]<m1)) i++;
        while ((ax[j]>m) || (ax[j]==m && ay[j]>m1)) j--;
        if (i<=j)
        {
            swap(ax[i],ax[j]);
            swap(ay[i],ay[j]);
            i++;j--;
        }
    }
    if (l<j) qsorta(l,j);
    if (r>i) qsorta(i,r); 
}

int main()
{
    freopen("factory.in","r",stdin);
    freopen("factory.out","w",stdout);
    scanf("%d%d",&n,&m);    
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d",&x[i],&y[i]);y[i]--;
    }
    memset(bz,false,sizeof(bz));
    for (int i=1;i<=n;i++)
    {
        bool pd=true;
        for (int j=1;j<=n;j++)
        {
            if (j!=i)
            {
                if (!bz[j] && x[i]<=x[j] && y[j]<=y[i])
                {
                    pd=false;
                    break;
                }
            }
        }
        if (pd==true)
        {
            ga++;
            ax[ga]=x[i];
            ay[ga]=y[i];
        }
        else
        {
            gb++;
            bx[gb]=x[i];
            by[gb]=y[i];
            bz[i]=true;
        }
    }
    qsorta(1,ga);
    memset(f,128,sizeof(f));
    f[0][0]=0;
    for (int i=0;i<=ga;i++)
    {
        for (int k=0;k<=min(i,m);k++)
        {
            for (int j=i+1;j<=ga;j++)
            {
                if (f[i][k]>=0)
                if (ay[i+1]-ax[j]+1>0)
                {
                    f[j][k+1]=max(f[j][k+1],f[i][k]+ay[i+1]-ax[j]+1);
                }
            }
        }
    }
    qsortb(1,gb);
    for (int i=1;i<=n;i++)
    {
        sum[i]=sum[i-1]+by[i]-bx[i]+1;
    }
    for (int i=0;i<=m;i++)
    {
        ans=max(ans,f[ga][m-i]+sum[i]);
    }
    printf("%d\n",ans);
} 

Guess you like

Origin www.cnblogs.com/RainbowCrown/p/11600443.html