南京理工大学第八届程序设计大赛 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;
}
将一个给定的数列,拆分成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;
}
相关文章推荐
- Ipad UI 设计规范
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- LeetCode *** 63. Unique Paths II
- HDUOJ 5667 Sequence
- php中require,include,use区分
- POJ 1458 Common Subsequence(最长公共子序列LCS)
- HDU1503:Advanced Fruits(LCS)
- VMware共享文件夹编译出现“Value too large for defined data type”错误的解决办法
- build-essential: 依赖: g++ (>= 4:4.3.1) 但是它将不会被安装
- UIDynamic 基础
- leetcode——63—— Unique Paths II
- reason: 'UITableView failed to obtain a cell from its dataSource'
- njust sequence(二分查找)
- HDU5667 Sequence(矩阵快速幂)
- iOS开发——纯代码界面(UITabBarController,UINavigationController,UIImageView)
- LeetCode-51&52.N-Queens
- HDU 5667 Sequence【矩阵快速幂】【欧拉函数】
- HDU-5667 Sequence (矩阵快速幂)
- leetcode—— 62——Unique Paths
- SoapUI + Selenium Webdriver 自动化测试学习