hdu 2611 DFS
来源:互联网 发布:页面静态化 java 编辑:程序博客网 时间:2024/05/18 03:34
日!
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <set>using namespace std;#define MAX 0x3f3f3f3fstruct Node{int num, index;};int N, P, cnt, record[110];Node nodes[110];int cmp( const void *a, const void *b ){if( ((Node*)a)->num == ((Node*)b)->num ){return ((Node*)a)->index - ((Node*)b)->index;} return ((Node*)a)->num - ((Node*)b)->num;}void show( int pos ){printf( "%d", record[0] );for( int i = 1; i <= pos; i++ ){printf( " %d", record[i] );}cout << endl;}bool DFS( int pos, int deep, int maxdeep, int preindex ){if( cnt >= P ){return true;}bool f = false;int pre;for( int i = pos; i < N; i++ ){if( nodes[i].index > preindex ){if( !f ){f = true;pre = nodes[i].num;}else if( pre == nodes[i].num ){continue;}pre = nodes[i].num;record[deep] = nodes[i].num;if( deep == maxdeep ){show( deep );cnt++;if( cnt == P ){//这里不能少。。。。。。。。return true;}}else if( DFS( i + 1, deep + 1, maxdeep, nodes[i].index ) ){return true;}}}return false;}int main(){while( scanf( "%d%d", &N, &P ) != EOF ){for( int i = 0; i < N; i++ ){scanf( "%d", &nodes[i].num );nodes[i].index = i;}qsort( nodes, N, sizeof( Node ), cmp );cnt = 0;for( int i = 0; i < N; i++ ){if( DFS( 0, 0, i, -1 ) ){break;}if( cnt >= P ){break;}}cout << endl;}return 0;}
0 0
- hdu 2611 DFS
- HDU DFS
- 【DFS】HDU
- HDU DFS
- hdu 2611(dfs判重)
- hdu 2611 dfs+经典判重cut
- HDU-2610 && HDU-2610 (dfs)
- HDU 1864 (DFS)
- hdu 1258 DFS
- hdu 1045 DFS+回溯
- hdu--1342 lotto (dfs)
- hdu 1010(DFS)
- hdu 1501(dfs)
- hdu 1010DFS
- HDU 3720 DFS
- hdu 2212 DFS
- hdu 1181 dfs
- DFS 剪枝 hdu 1010
- HTML特效代码
- Android Wifi 手机连接调试
- java并发编程学习总结(基础篇)
- html 表单 form 横向排列
- C语言编写的万年历~ 共同进步~~
- hdu 2611 DFS
- C++库介绍-标准库、类库
- python 学习笔记13-----多线程编程
- MYSQL C API 入门教程
- Android菜鸟的成长笔记(11)——Android中的事件处理
- 20140216
- Java 默认修饰符 总结
- 黑马程序员—23—java面试:有关交通灯学习笔记和学习心得
- 简述UML之活动图