您的位置:首页 > 产品设计 > UI/UE

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

2016-04-17 21:23 381 查看
题目的:

将一个给定的数列,拆分成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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: