poj 1989 The Cow Lineup 最短非子序列问题
来源:互联网 发布:怎么禁止装软件 编辑:程序博客网 时间:2024/06/05 11:51
本题的关键是发现最短非子序列和长度为n的序列之间的关系,规律是在长度为n的排列中找出囊括1到k的排列的个数 num,那么长度为num的序列都是长度为n的子序列,因为都可以从num囊括1到k的排列中挑选出符合要求的数字组成长度为num的序列 然后最短非子序列的长度为num + 1
如题中所给示例 1 5 3 2 5 1 3 4 4 2 5 1 2 3
(1 5 3 2 5 1 3 4)(4 2 5 1 2 3)[ ]
共有2个囊括1到k的排列,所以最短非子序列为3
#include <cstdio>#include <string.h>// 最短非子序列问题//规律是在长度为n的排列中找出囊括1到k的排列的个数//如题中所给示例 // 1 5 3 2 5 1 3 4 4 2 5 1 2 3 //(1 5 3 2 5 1 3 4)(4 2 5 1 2 3)[]//共有2个囊括1到k的排列,所以最短非子序列为3#define N 10001 bool num[N];int main(){int n ,k, len = 0, size = 0, x;scanf("%d%d", &n, &k);for(int i = 1; i <= n; i++){scanf("%d", &x);if(num[x] == false){num[x] = true;size++;}if(size == k){memset(num, 0, sizeof(num));len++;size = 0;}}printf("%d\n", len + 1);return 0;}
0 0
- poj 1989 The Cow Lineup 最短非子序列问题
- poj 1989 The Cow Lineup
- poj 1989 The Cow Lineup
- poj-1989 The Cow Lineup
- poj 1989 The Cow Lineup 数组
- POJ 1989 The Cow Lineup [dp]
- POJ 1989 The Cow Lineup 笔记
- BZOJ 3377 [Usaco2004 Open]The Cow Lineup 奶牛序列
- POJ1189 HDU271 The Cow Lineup
- POJ1989 The Cow Lineup 额,贪心??
- The Cow Lexicon POJ
- Balanced Lineup+POJ+RMQ问题
- POJ1989 The Cow Lineup——贪心+扫描技巧
- poj 3267 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- poj 3267 The Cow Lexicon
- poj 3276 The Cow Lexicon
- POJ 3267 The Cow Lexicon
- 【翻译】“PE文件格式”1.9版 完整译文(附注释)
- 【Leetcode】Valid Palindrome
- 虚幻引擎4(Unreal Engine 4/UE4)正式发布!每月19美元
- 位运算简介及实用技巧(四):实战篇
- 人的健康一天之中最重要的时刻
- poj 1989 The Cow Lineup 最短非子序列问题
- Jquery插件--easyUI属性汇总
- Codeforces Round #136 (Div. 2) D. Little Elephant and Array
- linux 的ifconfig命令
- mysql event 即 mssql的job作业
- 蓝桥杯- 九宫重排
- 2007年4月计算机等级考试C++考试试卷参考答案及解析
- 指针数组 多维数组C语言
- PHP多维数组eval与循环实现以及效率(真实测试过,研究了半天后来才找到的资料,对组合报表很有用)