http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1241&judgeId=548566
这道题真的是很机智啊,代码很短
就是要求 连续的 递增的 数列,然后用总的减

#include"bits/stdc++.h"
using namespace std;
const int maxn=5e4+5;
int dp[maxn];//dp[i]表示i之前连着有多少个连续的数
int main()
{
    int N;
    while(cin>>N)
    {
        memset(dp,0,sizeof(dp));
        int t,Max=-1;
        for(int i=1;i<=N;i++)
        {
            cin>>t;
            dp[t]=dp[t-1]+1;
            Max=max(Max,dp[t]);
        }
        cout<<N-Max<<endl;
    }
}