题目大意:在给定的序列中找到固定个数的递增的子序列,如果子序列的总个数少于要求的个数,那么就把所有的子序列输出即可。

题解:本来题目也不太看得懂,在别人的博客看了许久才懂,剪枝和判重也不大会,于是暂时先把它给看懂。一个有效的剪枝,一个子串如果不成立,那么比其大的子串显然不成立,所以剪枝。

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n,p,len,count_num;
int num[1001];
bool flag;
typedef struct
{
int n,pos;
}Tem;
Tem tem[1001];
bool check(int s,int e)
{
for(int i = s+1; i < e; i++)
if(num[i]==num[e])return false;
return true;
}
void print_sequence(int length)
{
for(int i = 0; i < length-1;i++)
cout<<tem[i].n<<" ";
cout<<tem[length-1].n<<endl;
}
void dfs(int dep,int pos)
{
if(count_num >= p)return;
if(dep==len)
{
count_num++;
flag = true;
print_sequence(len);
return;
}
for(int i=pos;i<n;i++)
{
if((dep!=0&&tem[dep-1].n<=num[i])||dep==0)
{
if(dep==0&&!check(-1,i))
continue;
if(dep!=0&&!check(tem[dep-1].pos,i))
continue;
tem[dep].n = num[i];
tem[dep].pos = i;
dfs(dep+1,i+1);
}
}
return;
}
int main()
{
while(cin>>n>>p)
{
for(int i=0;i<n;i++)
cin>>num[i];
count_num = 0;
for(int i = 1;i < n;i++)
{
flag=false;
len = i;
dfs(0,0);
if(count_num>=p||!flag)break;
}
cout<<endl;
}
return 0;
}

HDU 2610 Sequence one的更多相关文章

  1. HDU 3397 Sequence operation(线段树)

    HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变 ...

  2. HDU 2610 (自己完全找不到思路) Sequence one

    搜索虐我千百遍,我待搜索...好吧,我还木有初恋 题意: 我开始理解题意就理解偏了,Orz 题中有n个元素构成的序列,求出前p个非递减子序列.子序列是先按长度排序的,然后按原序列先后位置排序的. 这里 ...

  3. HDU 5919 Sequence II(主席树+逆序思想)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  4. hdu 5146 Sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...

  5. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

  6. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

  7. hdu 1711Number Sequence (KMP入门,子串第一次出现的位置)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu 3397 Sequence operation(线段树:区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3397 题意:给你一个长度为n的0,1序列,支持下列五种操作, 操作0(0 a b):将a到b这个区间的 ...

  9. HDU 1141---Brackets Sequence(区间DP)

    题目链接 http://poj.org/problem?id=1141 Description Let us define a regular brackets sequence in the fol ...

随机推荐

  1. jsp-forward跳转

    在Web中可以使用<jsp:forward>指令,将一个用户的请求(request)从一个页面传递到另一个页面,即完成跳转的操作. 1.调整前页:tiaozhuan_a.jsp 代码: & ...

  2. 转场动画1-Push 动画

    先上效果图: 这篇文章完全是为造轮子制作:原作者是码农界的吴彦祖 作者视频下载地址 好的,我梳理一下思路: 理清思路 ||转场动画可以理解为一个对象,在这个对象里封装了一个动画.具体的我们跟着代码走 ...

  3. IO库 8.2

    题目:编写一个测试函数,将cin作为参数传入. #include <iostream> using std::istream; istream& func(istream& ...

  4. SGU 149. Computer Network( 树形dp )

    题目大意:给N个点,求每个点的与其他点距离最大值 很经典的树形dp...很久前就想写来着...看了陈老师的code才会的...mx[x][0], mx[x][1]分别表示x点子树里最长的2个距离, d ...

  5. C#学习日志 day 5 ------ windows phone 8.1真机调试手机应用

    在vs2013中,可以写windows phone 8.1的程序,但是调试时需要用到windows自带的虚拟机hyper-V 正版的系统开启hyper—V的时候不会有问题,但是盗版的系统可能导致系统不 ...

  6. pyhton

    http://panda.www.net.cn/cgi-bin/check.cgi?area_domain= http://whois.chinaz.com/ beautifulsoup4 impor ...

  7. Windows 7各版本的主要功能区别是什么 有何不同

    Windows 7包含6个版本,分别为Windows 7 Starter(初级版).Windows 7 Home Basic(家庭普通版).Windows 7 Home Premium(家庭高级版). ...

  8. HttpWebRequest使用注意(发生阻塞的解决办法)

    原文 http://www.cnblogs.com/Fooo/archive/2008/10/31/1323400.html HttpWebRequest使用注意(发生阻塞的解决办法) , count ...

  9. UIWindow 详解

    UIWindow对象是所有UIView的根视图,管理和协调的应用程序的显示.分发事件给View.UIWindow类是UIView的子类,可以看作是特殊的UIView.一般应用程序只有一个UIWindo ...

  10. POJ 3294 Life Forms(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...