hdu 2610
来源:互联网 发布:火炬之光2mac版本更新 编辑:程序博客网 时间:2024/06/09 18:15
深搜
#include<stdio.h>int n, p, len, cnt;bool flag;int num[1024];struct{ int n, pos;}tmp[1024];bool isRepet(int s, int e){ for(int i = s + 1; i < e; i++) if(num[i] == num[e]) return true; return false;}void print(int len){ for(int i = 0; i < len - 1; i++) printf("%d ",tmp[i].n); printf("%d\n",tmp[len - 1].n);}void dfs(int dep, int pos){ if(cnt >= p) return; if(dep == len){ cnt ++; flag = true; print(len); return; } for(int i = pos; i < n; i++){// i < n! if(dep != 0 && tmp[dep-1].n <= num[i] || dep == 0){ if(dep == 0 && isRepet(-1, i)) continue; if(dep != 0 && isRepet(tmp[dep - 1].pos, i)) continue; tmp[dep].n = num[i]; tmp[dep].pos = i; dfs(dep + 1, i + 1); } }}int main(){ while(~scanf("%d %d", &n, &p)){ for(int i = 0; i < n; i++) scanf("%d", &num[i]); cnt = 0; for(int i = 1; i < n; i++){ flag = false; len = i; dfs(0,0); if(cnt >= p || !flag) break; } puts(""); } return 0;}
0 0
- hdu 2610
- hdu 2610
- HDU-2610 && HDU-2610 (dfs)
- HDU 2610 Sequence one
- hdu 2610 (dfs)
- hdu 2610and2611
- HDU 2610 Sequence one
- 【HDU】2610 Sequence one
- hdu 2610 全排列
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- android之AlertDialog
- glassfish4.0配置
- box2d实力触摸不规则图片
- 第162天
- WebRTC中的AppRTCDemo.apk简单分析
- hdu 2610
- numpy nonzero使用方法
- ZOJ3469:Food Delivery(区间DP)
- 竖式问题(sprintf函数,strchr)
- 二叉树按层次遍历--队列实现
- HDU 4024 Dwarven Sniper’s hunting (计算几何-其它,搜索-二分)
- Java开发中的23种设计模式详解
- Vision引擎中环境地形技术信息
- 黑马程序员——集合-Cllection