Sequences Gym - 101020D (典型DP)

没想到我会卡到这道dp题上

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.

 

题目意思就是使得找出一个最长上升子序列且这个子序列每两个数字之间差1

典型的DP题

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[20005];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        memset(dp,0,sizeof(dp));
        int ans=0;
        int k;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&k);
            dp[k]=max(dp[k],dp[k-1]+1);
            ans=max(ans,dp[k]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值