HDU 2610 Sequence one
题目大意:在给定的序列中找到固定个数的递增的子序列,如果子序列的总个数少于要求的个数,那么就把所有的子序列输出即可。
题解:本来题目也不太看得懂,在别人的博客看了许久才懂,剪枝和判重也不大会,于是暂时先把它给看懂。一个有效的剪枝,一个子串如果不成立,那么比其大的子串显然不成立,所以剪枝。
#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的更多相关文章
- 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变 ...
- HDU 2610 (自己完全找不到思路) Sequence one
搜索虐我千百遍,我待搜索...好吧,我还木有初恋 题意: 我开始理解题意就理解偏了,Orz 题中有n个元素构成的序列,求出前p个非递减子序列.子序列是先按长度排序的,然后按原序列先后位置排序的. 这里 ...
- HDU 5919 Sequence II(主席树+逆序思想)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- hdu 5146 Sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...
- HDU 6395 Sequence 【矩阵快速幂 && 暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 5312 Sequence(数学推导——三角形数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others) ...
- hdu 1711Number Sequence (KMP入门,子串第一次出现的位置)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3397 Sequence operation(线段树:区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3397 题意:给你一个长度为n的0,1序列,支持下列五种操作, 操作0(0 a b):将a到b这个区间的 ...
- HDU 1141---Brackets Sequence(区间DP)
题目链接 http://poj.org/problem?id=1141 Description Let us define a regular brackets sequence in the fol ...
随机推荐
- ios不同版本下的UILabel自动换行问题
@interface ThreadPreviewCell : UITableViewCell @property (nonatomic, strong) UILabel *titleLabel; @e ...
- SecureCRT, SecureFX连接Linux时中文乱码解决办法
SecureCRT可以在GUI界面设置,但SecureFX没有设置界面.不过可以直接在配置文件中修改. 1. 找到配置文件夹(选项--全局选项,常规下的配置文件夹),默认是:C:\Documents ...
- 【转】几个常用的Oracle存储过程
http://blog.bossma.cn/database/some-oracle-storing-process/ 几个常用的Oracle存储过程 发布时间:2008年1月6日 / 分类:Data ...
- MySQL 二进制日志过滤
binlog_do_db; binlog_ignore_db; 这个两个参数是用来控制对哪个数据库的更改要记录日志:下面以binlog_ignore_db为例子. 假如binlog_ignore_db ...
- 使用 PyQt 转换网页到 PDF(使用QtWebKit加载完毕后,打印整个窗口就行了,真简单!)
import sys try: from PyQt4 import QtWebKit from PyQt4.QtCore import QUrl from PyQt4.QtGui import QAp ...
- Codeforces 700B Connecting Universities(树形DP)
[题目链接] http://codeforces.com/problemset/problem/700/B [题目大意] 给出 一棵n个节点的树, 现在在这棵树上选取2*k个点,两两配对,使得其配对的 ...
- 有道翻译API
轻奢侈品_百度百科 轻奢侈品 有道翻译API 有道翻译API申请成功 API key:72763558 keyfrom:lexus-studio
- c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow
c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow fcgio.cpp:50: error ...
- FastCGI | FastCGI -
FastCGI | FastCGI - FastCGI About FastCGI FastCGI is simple because it is actually CGI with only a f ...
- javascript date 加一天(明天)
end = new Date(); end = new Date(end.valueOf() + 1*24*60*60*1000);