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 ...
随机推荐
- java中Set类接口的用法
在Java中使用Set,可以方便地将需要的类型,以集合类型保存在一个变量中.主要应用在显示列表. Set是一个不包含重复元素的collection.更确切地讲,set 不包含满足 e1.equals( ...
- Pycharm中如何加载多个项目?
今天在使用Pycharm工具练习Python时遇到一个疑问:在已存有项目A工程的前提下如何新建另一个项目B,且两者并存? 基本操作步骤: 在File下拉项中选择"New Project&qu ...
- GCD hdu2588
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- http://codeforces.com/contest/349
A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Python数据分析(二): Numpy技巧 (3/4)
numpy.pandas.matplotlib(+seaborn)是python数据分析/机器学习的基本工具. numpy的内容特别丰富,我这里只能介绍一下比较常见的方法和属性. 昨天晚上发了第一 ...
- 支持向量机SVM(一)
[转载请注明出处]http://www.cnblogs.com/jerrylead 1 简介 支持向量机基本上是最好的有监督学习算法了.最开始接触SVM是去年暑假的时候,老师要求交<统计学习理论 ...
- Windows下Apache添加SSL模块
参考资料:http://www.yuansir-web.com/2011/05/12/hello-world/测试环境:windows2003 32位 + Apache2.4 + PHP5.4 一.准 ...
- Request.QueryString("id")与Request("id")区别
Request从几个集合取数据是有顺序的,从前到后的顺序依次是 QueryString,Form,最后是ServerVariables.Request对象按照这样的顺序依次搜索这几个集合中的变量,如果 ...
- js基于谷歌地图API绘制可编辑圆形与多边形
之前的工作中需要在谷歌地图上绘制可编辑多边形区域,所以基于谷歌地图API封装了个html页面,通过调用js绘制多边形并返回各点的经纬度坐标:当然首先你要保证你的电脑可以打开谷歌地图... 新建一个ht ...
- HDU1423 LCIS
1,先离散化,然后DP: 注意这个解法中,dp[i][j][k]代表a序列中前i个和b序列中前j个数结尾为k或小于k时的最大. 但是由于i是单增(一次1->n),而j反复变化(多次1->m ...