Problem Description
Search is important in the acm
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.
Input
The input contains multiple test
cases.

Each test case include, first two integers n, P. (1

Output
For each test case output the sequences
according to the problem description. And at the end of each case
follow a empty line.
Sample Input
3
1 3
3
1 3
4
100 
1 2 3
2
Sample Output
1
1

1
1

1
1
2
2
1 2
1 2
题意:给你一个任意数列,让你求出所有的递增子序列;
解题思路:深搜,以长度为搜索的变量,从1-n,n为当前搜索的长度;每搜索到一个序列输出一个序列;后面这几个题越来越难写了0.0;
感悟:不能看题解,越看越毁啊!
代码:
#include
#include
#include
#include
#include
#define maxn 1001
using namespace std;
int n,p,pos[maxn],ans,len,pot[maxn],op[maxn];
bool flag;
void printf(int len)
{
    for(int i=0;i
     
  printf(i?" %d":"%d",pot[i]);
    printf("\n");
}
bool check(int s,int e)
{
    for(int i=s+1;i
    if(pos[i]==pos[e])
     
  return false;//如果这个数在前面出现过了就不能用了
    return true;
}

void dfs(int cur,int t)//cur表示当前需要派到第几位了,t表示当前搜索到第几位了
{
    if(ans>=p)
return;//大于p的就不需要搜了
    if(cur==len)
    {
     
  ans++;
     
  flag=true;
     
  printf(len);//将数组输出
     
  return;
    }
    for(int i=t;i
    {
     
 
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开始搜的,而是从你找到这个数的下一位开始搜的
     
  }
    }
    return ;
}
int main()
{
    //freopen("in.txt", "r",
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");
    }
    return 0;
}

Sequence one的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [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 ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  10. 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 ...

随机推荐

  1. Java开发中遇到的问题

    head丢失 html的dtd不对 Integer数据类型 使用==比较 这个肯定错(事后才知道) sql语句处理分组的时候,在本地服务使用没问题,在服务器上出现sql异常 group by语句规范, ...

  2. AngularJS 框架

    AngularJS 通过 指令 扩展了 HTML,且通过 表达式 绑定数据到 HTML. [Angular JS表达式]  1.Angular JS使用双{{}}绑定方式.用于将表达式的内容输出到页面 ...

  3. 安装Appium

    1.Appium官方网站:http://appium.io/ 拉到页面底端显示下面一段描述: > brew install node # get node.js > npm install ...

  4. 【JVM命令系列】jmap

    命令基本概述 Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.打印出某个java进程(使用pid)内存内的,所有'对象'的情况(如:产生那些对象,及其数量 ...

  5. uvalive 3029 City Game

    https://vjudge.net/problem/UVALive-3029 题意: 给出一个只含有F和R字母的矩阵,求出全部为F的面积最大的矩阵并且输出它的面积乘以3. 思路: 求面积最大的子矩阵 ...

  6. http://codeforces.com/contest/834

    A. The Useless Toy time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. python pyqt

    一.控件 1.单行文本框QLineText clear() 清除文本框中的内容contextMenuEvent() 右键菜单事件copy() 复制文本框中的内容cut() 剪切文本框中的内容paste ...

  8. zoj1871steps 数学 水

                                                                                            zoj1871 题目大意 ...

  9. Java面向对象 线程技术 -- 下篇

     Java面向对象 线程技术 -- 下篇 知识概要:              (1)线程间的通信           生产者 - 消费者 (2)生产者消费者案例优化 (3)守护线程 (4)停止线 ...

  10. Myeclipse 配置Tomcat 出现 “Value must be an existing directory”错误

    今天上午配了一下本机上的Myeclipse的tomcat,因为我本机上有两个版本的myeclipse,一个是用来公司开发的,一个是自己玩的,本机上装了两个版本jdk和两个版本的tomcat.配置自己玩 ...