HDU 1027 Ignatius and the Princess II
来源:互联网 发布:广东省深圳市 阿里云 编辑:程序博客网 时间:2024/06/06 14:05
这题我使用DFS来解决的,但是每次我写DFS的时候总是坑在递归结束的条件上,每次都要纠结,这次也不例外。不过总算解决了。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<stack>#include<queue>using namespace std;const int N=1005;int ans[N];bool visited[N];int n,m;bool dfs(int id){ if(id==n+1)//就是这里太纠结了 { m--; if(m==0) return true; return false; } for(int i=1;i<=n;i++) { if(visited[i]) continue; visited[i]=true; ans[id]=i; if(dfs(id+1)) return true; visited[i]=false; } return false;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { memset(visited,false,sizeof(visited)); dfs(1); for(int i=1;i<n;i++) printf("%d ",ans[i]); printf("%d\n",ans[n]); } return 0;}
0 0
- hdu 1027 ignatius and the princess ii
- HDU 1027 Ignatius and the Princess II
- HDU 1027 ( Ignatius and the Princess II )
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- Ignatius and the Princess II hdu 1027
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- [LeetCode]Restore IP Addresses
- UIScrollView用法
- Emacs 代码补全 AutoComplete
- 愚人节的礼物
- opencv_linux_install and build
- HDU 1027 Ignatius and the Princess II
- 如何构建超强伸缩性的游戏服务器而集容错、负载均衡和无限伸缩性于一身
- Java泛型
- GDT 全局描述符表 数据结构
- Android学习十二---在android上实现图像匹配
- android 文件保存到应用和sd卡中
- CardView初体验
- sdut 图结构练习——判断给定图是否存在合法拓扑序列
- 数据库事务的ACID隔离级中P0(脏写)和P4(更新丢失)的区别