poj 2245lotto(dfs)
2014-12-19 23:21
204 查看
A题的感觉是真爽啊,昨天大致看了看这道题目,觉得挺不容易的,今天仔细想了想,没想到还挺简单的,经典的深度优先遍历,加回溯,好像深度优先遍历基本上都会跟回溯连在一起诶,是我理解错了么?难道深度优先遍历本身就有回溯这部分?我觉得深度优先遍历就是遍历到最后的,要是没有找到答案,或者还想找其他的答案,就要进行回溯了,这题不解释了,好好想想吧,挺简单的,明天考四级了,英语听力其实压根听不懂诶,对于河南考生,英语听力有点坑,我们高考可是不考的啊
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
,没事儿,明天好好做就行,没那么难过吧,好好考,发挥出应有的水平就好
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
,没事儿,明天好好做就行,没那么难过吧,好好考,发挥出应有的水平就好
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
#include<stdio.h> #include<stdlib.h> #include<string.h> int n,x,visit[20],b[20],a[20]; void dfs(int cur) { if(x==7) { for(int i=1;i<=6;i++) { printf("%d",b[i]); if(i!=6) printf(" "); } printf("\n"); } else { for(int k=cur;k<=n;k++) { if(!visit[k]) { visit[k]=1; b[x++]=a[k]; dfs(k+1); visit[k]=0; x--; } } } } int cmp(const void *p,const void *q) { return *(int *)p-*(int *)q; } int main() { int i; while(scanf("%d",&n),n!=0) { memset(visit,0,sizeof(visit)); x=1; for(i=1;i<=n;i++) scanf("%d",&a[i]); qsort(a+1,n,sizeof(a[1]),cmp); dfs(1); printf("\n"); } return 0; }
相关文章推荐
- POJ 2245 Lotto(水水的dfs)
- POJ 题目2245 Lotto(DFS水)
- zoj 1089 || poj 2245 Lotto(DFS~)
- POJ 2245 Lotto DFS
- POJ 2245 Lotto DFS
- POJ 2245 Lotto dfs
- POJ 2245 Lotto-DFS-(回溯法)
- poj 2245 Lotto dfs
- ACM POJ 2245Lotto解题报告
- poj 2245 Lotto
- POJ 2245 Lotto (枚举)
- poj 1496(1850)/2245 全组合打表(一种字符编码/Lotto)
- poj 2245 Lotto
- poj 2245 Lotto
- Poj 2245—LOTTO
- POJ 2245 Lotto
- POJ 2245 Lotto
- 周赛 POJ 2245 Lotto
- hdu1342 && poj 2245 Lotto
- hdu 1342 and poj 2245 Lotto,dfs