sequence

sequence

Time Limit: 1000MS

Memory Limit: 65536KB

Description

将一个给定的数列,拆分成K个不降序列,每个数出现且只出现一次,且在各序列中各个数相对于原数列的相对顺序不变。如7 6 9 8 10可以拆成 7 9 10和6 8。求最小的K值。

Input

第一行输入一个整数T(1 <= T <= 100),表示接下来T组测试数据,每组两行,第一行为n,代表数列长度(1<=n<=10000)接下来一行有n个数,空格分隔(每个数<=50000)。

Output

对每组数据输出一个最小的K值。

Sample Input

2
5
7 6 9 8 10
5
5 4 3 2 1

Sample Output

2
5
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int height[10000];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        int number;
        int p = 0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&number);
            int tmp_index = -1;
            for (int i = 0; i <p; i++)
            {
                if(number>=height[i] && (tmp_index == -1 || height[tmp_index] < height[i]))
                {
                tmp_index = i;
                }
            }
            if(tmp_index != -1)//替换需要更新的数
            {
                height[tmp_index] = number;
            }
            else
            height[p++]= number;//有非递减的就加一
        }
        cout<<p<<endl;
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值