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 ...
随机推荐
- C#设计模式之五创建者模式(Builder)【创建型】
一.引言 今天我们要讲讲Builder模式,也就是建造者模式,当然也有叫生成器模式的.在现实生活中,我们经常会遇到一些构成比较复杂的物品,比如:电脑,它就是一个复杂的物品,它主要是由CPU.主板.硬 ...
- HDFS概述(3)————HDFS Federation
本指南概述了HDFS Federation功能以及如何配置和管理联合集群. 当前HDFS背景 HDFS主要有两层: 1.Namespace (1)包含目录,文件和块. (2)它支持所有命名空间相关的文 ...
- ClassLoader类加载机制&&JVM内存管理
一.ClassLoader类加载机制 在java中类加载是遵循委派双亲加载的:通过调用loadClass方法逐级往上传递委派加载请求,当找不到父ClassLoader时调用其findClass方法尝试 ...
- hdu1878判断欧拉回路
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HTML5基础知识及相关笔记
HTML5基础 1.1HTML文件的基本结构和W3C标准 1.1.1HTML简介 HTML是一种描述网页的语言,一种超文本标记的语言! 1.1.2HTML文件的基本结构 头部(head) 头部是网页的 ...
- 对python编程的初步理解
一直以来零零散散有听过python,这周终于下定决心学python了.在网上了买个套视频教程,内容分周次学习,有详细的讲解.本人觉得非常好.这里谈谈一下第一周的学习的笔记.望路过的大神给予指正,不胜感 ...
- [js高手之路]html5 canvas动画教程 - 边界判断与小球粒子模拟喷泉,散弹效果
备注:本文后面的代码,如果加载了ball.js,那么请使用这篇文章[js高手之路] html5 canvas动画教程 - 匀速运动的ball.js代码. 本文,我们要做点有意思的效果,首先,来一个简单 ...
- Java历程-初学篇 Day08 数组
一,什么是数组 所谓数组,是相同数据类型的元素按一定顺序排列的集合.若将有限个类型相同的变量的集合命名,那么这个名称为数组名.组成数组的各个变量称为数组的分量,也称为数组的元素,有时也称为下标变量.用 ...
- jQuery中下拉select、复选checkbox、单选radio的操作代码
//select $("#Icon") //对象 $("#Icon").val() //取值 $("#Icon").val("fa ...
- ASP.NET没有魔法——ASP.NET MVC 与数据库大集合
ASP.NET没有魔法——ASP.NET与数据库 ASP.NET没有魔法——ASP.NET MVC 与数据库之MySQL ASP.NET没有魔法——ASP.NET MVC 与数据库之ORM ASP.N ...