南京理工大学第八届程序设计大赛 sequence Dilworth定理

题目的:

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

题目。。。我就暴力了啊!强行模拟啊!!我感觉这样就是对的啊!!!


PZ告诉我这样不对,因为数据水。。正确的做法是利用Dilworth定理


我不知道那个定理。。我就暴力过了。。



#include <iostream>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define read(a) scanf("%d", &(a))

int a[10010];
map<int, int>g;
map<int, int>:: iterator it;
int n;

void doit()
{
	int ans = 0;
	g.clear();
	int inf = 1000000;
	g[inf] = 0;
	for (int i = 0 ; i != n; ++ i)	a[i] = -a[i];
	for (int i = 0; i != n;++i)// 不增
	{
		it = g.lower_bound(a[i]);
		//cout << it -> first<<" "<< it->second << endl;
		if (it -> first == inf)
		{
			++ ans;
		}
		g.erase(it);
		if (g.find(inf) == g.end())	g[inf] = 0;
		g[a[i]] = 0;
	}
	printf("%d\n", ans);
}

int main()
{
	int T;
	read(T);
	while (T--)
	{
		read(n);
		for (int i = 0; i != n; ++ i)	read(a[i]);
		doit();
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值