D - Sequences Gym - 101020D(Dp问题)

One of the most wonderful qualities of an ACMer is to be multi interests so he combines multiple qualifications and hobbies not just coding. Hussain is one of the most qualified ACMers to mention when talking about hobbies and other domains of personality training despite of his qualifications in ACM problem solving and math. It’s very known about Hussain his obsession in hunting and shooting, he used to pass hours training on empty cans in his childhood. These days, Hussain became a professional and still challenge others in this game, but for his bad luck he accidentally challenged a professional ACMer, without mentioning the name, so this ACMer made a game for Hussain. He numbered N targets for Hussain with random numbers and challenged him to shoot the minimum number of targets so the remaining numbers will form a sequence of increasing (by one) numbers in their current order. Example: if there is 6 targets numbered as follow: 2 5 7 3 2 4 Hussain will shoot 5,7 and the second 2 remaining for 2 3 4. Now, Hussain will focus on shooting, we will help him and focus on the targets he must shoot. But No! Hussain is an very good ACMer, we will make it hard for him and just tell him the number of the remaining targets in the sequence.

Input
First line contain an integer T represents the number of test cases 0 < T < 100, each test case consists of two lines, the first one is an integer 0< N < 20000 represents the number of targets, then followed by the second line that contains N numbers each number 0 < Xi < 20000 represents the number written on the i’th target.

Output
For each test case print one number represents the remaining sequence’s length can be created by the input where it should be the maximum length and each number of it follow its previous by 1.

Examples

Input

4
6
2 5 7 3 2 4
7
2 18 65 33 11 5 4
5
2 7 5 9 3
5
9 8 7 10 11

Output

3
1
2
3

Note
Please consider a large input file.

#include<bits/stdc++.h>

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<cstdlib>

using namespace std;
int dis[22000];
int main()
{
       int t;
       cin>>t;
       while(t--)
       {
            int n;
            cin>>n;
            int i;
            int maxx=0;
            memset(dis,0,sizeof(dis));
            for(i=0; i<n;  i++)
            {
                 int x;
                 scanf("%d",&x);
                 dis[x] = 1;
                 dis[x] = dis[x] + dis[x-1];
                 if(maxx<dis[x])
                 maxx = dis[x];
            }
            cout<<maxx<<endl;
       }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值