Sequence two(hdu2611dfs)
来源:互联网 发布:轻小说 知乎 编辑:程序博客网 时间:2024/06/06 18:39
题意:同2610一样,但是最后的输出序列要是有序的
思路:dfs,你原序列是什么,dfs出来就是什么,如果想输出的序列式有序的,先对原序列排序,保存原序列的下标。
搜索的时候和2610一样,多了一个判断条件,序列是递增的,下标也是递增的,还要判断他的下标是否递增,如果是符合条件
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int count_ = 0,len,n,p;struct number{ int num,ind; int pos;}path[100010];struct numbe{ int n; int pos;}num[1001];void dfs(int dep,int pos,int last){ bool flag = false; if(count_ >= p) return; if(dep == len) { count_++; int i; for(i = 0; i < len-1; i++) printf("%d ",path[i].num); printf("%d\n",path[i].num); return ; } int i,pre; for(i = pos; i < n; i++) { if(num[i].pos > last) { if(!flag) { flag = true; pre = num[i].n; } else if(pre == num[i].n) { continue; } path[dep].num = num[i].n; pre = num[i].n; dfs(dep+1,i+1,num[i].pos); } } return ;}bool cmp(numbe a,numbe b){ if(a.n < b.n) return true; else if(a.pos < b.pos) return true; else return false;}int main(){ while(scanf("%d%d",&n,&p) != EOF) { int i; memset(num,0,sizeof(num)); for(i = 0; i < n ; i++) { scanf("%d",&num[i].n); num[i].pos = i; } sort(num,num+n,cmp); count_ = 0; for(i = 1; i < n; i++) { len = i; dfs(0,0,-1); } printf("\n"); } return 0;}
- Sequence two(hdu2611dfs)
- hdu2611 Sequence two 深搜
- HDU 2611 Sequence two
- acm 2 1025 Sequence two
- hdu 2611 Sequence two 4.3.6
- HDU Sequence two 2611 DFS搜索判重
- hdu 5288 OO’s Sequence(two point + rmq)
- hdu 5288 OO’s Sequence(two pointers)
- HDU 5806 NanoApe Loves Sequence Ⅱ two pointers
- HDU5806 NanoApe Loves Sequence Ⅱ BestCoder Round #86 two-pointer
- HDU5806 NanoApe Loves Sequence Ⅱ(尺取法\two pointers)
- HDU 2611 Sequence two (dfs + 重判 + 剪枝)
- sequence
- SEQUENCE
- Sequence
- sequence
- sequence
- Sequence
- C中的字节对齐
- OpenCL使用GPU滤波
- iOS多线程编程指南(附录)
- vim 中快捷键
- 例10.1 从键盘输入一些字符,逐个把它们送到磁盘上去,直到用户输入一个“#”为止。
- Sequence two(hdu2611dfs)
- dxSDK jun10与dx8的兼容问题
- 中小企业可以招募和挽留顶尖的IT人才的八种方法
- java对象转换成为json数据
- DirectCompute使用GPU滤波
- JavaScript字符串插入、删除、替换函数
- java与js代码互调方法
- 网址记录
- git将代码提交到远程分支(非主分支)