zoj 1089 Lotto
2014-02-26 03:24
591 查看
题目地址:zoj 1089
题目:就是生成组合。
用dfs来写, 其中“相邻的边”实际上就是每次可以选择把某一位放入输出组中,也可以选择不放进去。 形成一“路径选择二叉树”。
搜到了一条路径就“return” 来回溯
cnt-- 就是把当前节点pass掉了~
代码:
题目:就是生成组合。
用dfs来写, 其中“相邻的边”实际上就是每次可以选择把某一位放入输出组中,也可以选择不放进去。 形成一“路径选择二叉树”。
搜到了一条路径就“return” 来回溯
cnt-- 就是把当前节点pass掉了~
代码:
#include<iostream> #include<vector> using namespace std; int p[13]; //int vis[13]; int k; int cnt=0; int pout[13]; void dfs(int cur) { if(cnt==6) { for(int i=0;i<5;i++) cout<<pout[i]<<" "; cout<<pout[5]<<endl; return; } if(cur>=k) return ; pout[cnt++]=p[cur]; dfs(cur+1); cnt--; dfs(cur+1); } int main() { bool flag=0; while(cin>>k) { if(k==0) break; if(flag) cout<<endl; if(!flag) flag=1; for(int i=0;i<k;i++) { cin>>p[i]; } dfs(0); } }
相关文章推荐
- zoj 1089 Lotto
- Stanford - Cryptography I - Week 1-2 Programming Assignment
- linux下挂载硬盘!
- c++11 function_typetraits备忘
- hdoj1002--A + B Problem II
- unix/linux 系统实现多个进程监听同一个端口
- Linux下使用tmux
- Add Two number in Linked(forward order)
- CheckPalindrom int LinkedList
- 编译安装apache
- Linux中文件查找——find命令 推荐
- Apache Prefork、Worker和Event三种MPM
- Call to undefined function mb_detect_encoding()错误的处理方法
- window7使用windows Live Write来写51CTO博客
- mysql_connect报告”No such file or directory”错误的解决方法
- Access denied for user 'root'@'localhost' (using password: YES)
- 网站许久不管为什么排名越来越好
- Stanford - Cryptography I - Week 1-1 Programming Assignment
- hdoj1001--Sum Problem
- codeforces#231_div2_B Very Beautiful Number 高精度枚举