Sequence one
algorithm. When you want to solve a problem by using the search
method, try to cut is very important.
Now give you a number sequence, include n (<=1000) integers,
each integer not bigger than 2^31, you want to find the first P
subsequences that is not decrease (if total subsequence W is
smaller than P, than just give the first W subsequences). The order
of subsequences is that: first order the length of the subsequence.
Second order the sequence of each integer’s position in the initial
sequence. For example initial sequence 1 3 2 the total legal
subsequences is 5. According to order is {1}; {3}; {2}; {1,3};
{1,2}. {1,3} is first than {1,2} because the sequence of each
integer’s position in the initial sequence are {1,2} and {1,3}.
{1,2} is smaller than {1,3}. If you also can not understand ,
please see the sample carefully.
cases.
Each test case include, first two integers n, P. (1
according to the problem description. And at the end of each case
follow a empty line.
5
2
6
2
100
2
3
2
3
2
2
3
3
2
3
2
printf(i?" %d":"%d",pot[i]);
return false;//如果这个数在前面出现过了就不能用了
return;//大于p的就不需要搜了
ans++;
flag=true;
printf(len);//将数组输出
return;
if((cur&&pot[cur-1]<=pos[i])||!cur)
//1 不是第一位的并且可以用这个数
//2 是第一位的
{
if(!cur&&!check(-1,i))//第0位没法比较这个数在前没出现没出现过
//所以只能用-1来比较
continue;
if(cur&&!check(op[cur-1],i))//这才能比较
continue;
pot[cur]=pos[i];
op[cur]=i;//记录到第几位了
dfs(cur+1,i+1);//不是从t+1开始搜的,而是从你找到这个数的下一位开始搜的
}
stdin);
while(scanf("%d%d",&n,&p)!=EOF)
memset(pos,0,sizeof pos);
memset(pot,0,sizeof pot);
for(int i=0;i
scanf("%d",&pos[i]);
ans=0;
for(int i=1;i
{
flag=false;
len=i;
dfs(0,0);
if(ans>=p||!flag) break;
}
printf("\n");
Sequence one的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- python实现算24的算法
1.介绍 给定4个整数,数字范围在1-13之间,任意使用 + - * / ( ) ,构造出一个表达式,使得最终结果为24,这就是常见的算24的游戏.本文介绍用Python语言实现的两种方式.2.实现思 ...
- leetCode没那么难啦 in Java (二)
介绍 本篇介绍的是标记元素的使用,很多需要找到正确元素都可以将正确元素应该插入的位置单独放置一个标记来记录,这样可以达到原地排序的效果. Start 27.RemoveElement 删除指定元 ...
- hdu1166 敌兵布阵
敌兵布阵 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动 ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- vue-resource传参数到后端,后端取不到数据的问题
先上一段代码: this.$http.post('xxx',{Search_Text:this.search_text}).then(function(response){ // 响应成功回调 thi ...
- Zabbix(二) : Zabbix Server端配置文件说明
Zabbix Server端配置文件说明 # This is a configuration file for Zabbix Server process # To get more informat ...
- 使用python实现后台系统的JWT认证(转)
今天的文章介绍一种适用于restful+json的API认证方法,这个方法是基于jwt,并且加入了一些从oauth2.0借鉴的改良. 1. 常见的几种实现认证的方法 首先要明白,认证和鉴权是不同的.认 ...
- K相邻算法
刚开始学习机器学习,先跟这<机器学习实战>学一些基本的算法 ----------------------------------分割线--------------------------- ...
- 退出psql时,报psql_history的错
数据库版本:Enterprisedb 9.2(postgreSQL) 错误如下所示: postgres=# exitcould not save history to file "/opt/ ...
- Elixir游戏服设计五
在<Elixir游戏服设计一>里提到,按照系统功能划分成app要保证原子性很难, 现在想想也没那么难.保证原子性,无非就是需要某个单点去完成操作.那么选择玩家进程去做原子性工作就可以了. ...