首页 > 其他 > 详细

DP P1259

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

线性覆盖

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!