码迷,mamicode.com
首页 > 其他好文 > 详细

DP P1259

时间:2017-10-29 18:37:10      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:one   include   amp   scan   can   区间   cst   temp   oid   

线性覆盖

f[i]是到每个区间的末尾能吃到的最大桶数

水题

、、、、、、、、、、、、、、、、、、、、、、、、、、

#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int temp;

int n,f[2200];

int maxx=0;

struct mmm

{

    int one,another;

    int...

线性覆盖;

f[i]是到每个区间的末尾能吃到的最大桶数

水题

、、、、、、、、、、、、、、、、、、、、、、、、、、

#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int temp;

int n,f[2200];

int maxx=0;

struct mmm

{

    int one,another;

    int buckets;

}a[1200];

bool cmp(mmm x,mmm y)

{

    return (x.another<y.another);

}

void init()

{

    memset(f,0,sizeof(f));

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

    {

        scanf("%d%d",&a[i].one,&a[i].another);

        a[i].buckets=a[i].another-a[i].one+1;

    }

    memset(f,0,sizeof(f));

}

void work()

{

    sort(a+1,a+1+n,cmp);

    for(int i=1;i<=n;i++)//以最后一个区间的end作为i max

    {

        f[i]=a[i].buckets;

        maxx=max(f[i],maxx);

    }

    for(int i=2;i<=n;i++)

    {

        temp=0;

        for(int j=1;j<i;j++)

            if(a[i].one>a[j].another&&temp<f[j])

                temp=f[j];

        f[i]+=temp;

        maxx=max(maxx,f[i]);

    }

    printf("%d\n",maxx);

}

int main()

{

    init();

    work();

    return 0;

}

DP P1259

标签:one   include   amp   scan   can   区间   cst   temp   oid   

原文地址:http://www.cnblogs.com/Murs/p/7750489.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!