码迷,mamicode.com
首页 > 编程语言 > 详细

51nod 1241 特殊的排序

时间:2018-10-10 21:50:41      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:cstring   ring   return   std   set   scan   特殊   i+1   main   

本来以为是求LIS,结果发现这样的话就变成随便插入了。。。

不过通过这个可以推出正确的思路,就是LIS中还要满足相邻两项(ai)+1==(ai+1)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

int s[51000];
int main()
{
    int n,x,mx=0;
    scanf("%d",&n);
    memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        s[x]=s[x-1]+1;
        mx=max(mx,s[x]);
    }
    printf("%d\n",n-mx);
    return 0;
}

 

51nod 1241 特殊的排序

标签:cstring   ring   return   std   set   scan   特殊   i+1   main   

原文地址:https://www.cnblogs.com/AKCqhzdy/p/9768649.html

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