• 问题 G: 艰难取舍(dp)


    题目描述

    由于hyf长得实在是太帅了,英俊潇洒,风流倜傥,人见人爱,花见花开,车见车载。
    有一群MM排队看hyf。每个MM都有自己独特的风格,由于hyf有着一颗包容的心,所以,什么风格的MM他都喜欢……
    但是,hyf有一个特别的要求,他不希望总是看到风格得差不多的MM,更加特别的是,如果两个MM风格完全一样,hyf不会有任何意见。
    现在,hyf希望从去看他的MM中,去掉一些MM,从而使得相邻2个MM的风格值的差(绝对值)不为1。自然地,hyf希望去掉的MM越少越好。

    输入

    第一行一个整数N;
    第2~N+1行N个整数,第i个为ci。表示第i个MM的风格值。

    输出

    一个数,表示最少要去掉的MM数。

    样例输入 Copy

    6
    4
    2
    2
    1
    1
    1
    

    样例输出 Copy

    2
    

    提示

    对于30%的数据,N≤20
    对于70%的数据,N≤100,ci≤2000
    对于100%的数据,N≤1000,0≤ci≤2000
     
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<map>
    #include<string> 
    #include <math.h> 
    #include<memory.h>
    #include<cstring> 
    using namespace std;
    typedef long long ll; 
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    const int INF=0x3f3f3f3f;
    const int maxn=10110;
    int a[maxn],dp[maxn];
    int n;
    void inint(){
        cin>>n; 
        for(int i=1;i<=n;i++){
            cin>>a[i];
        } 
    }
    int main(){
        inint();
        int ma=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                if(abs(a[i]-a[j])!=1){
                    dp[i]=max(dp[i],dp[j]+1);
                }
            }
        }
        for(int i=1;i<=n;i++){
            ma=max(dp[i],ma);
        }
        cout<<n-ma<<endl;
    } 
  • 相关阅读:
    springboot 无法访问静态资源
    webrtc源码阅读理解一
    c++ include的顺序重要吗?
    简说yuv
    i420 转 nv21
    ffmpeg mp4 转 yuv、 y4m转yuv、mp4转y4m && ffplay 播放y4m、yuv
    mysql 查询json字符串条件
    Webpack4.X中sourcemap的配置 详解
    webpack如何打包生成的map文件不生效?
    vue中使用setInterval,移入暂停,移出继续
  • 原文地址:https://www.cnblogs.com/lipu123/p/12803883.html
Copyright © 2020-2023  润新知