codevs 2928 你缺什么
来源:互联网 发布:班徽设计软件 编辑:程序博客网 时间:2024/05/16 18:49
读完题后基本就能确定深度优先搜索了。。
剩下的细节自己填补即可。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int N;int ans[10000+2],x[10000+2];bool flag[10000+2];void DFS(int n){if(n>N){printf("%d",ans[1]);for(int i=2;i<=N;++i)printf(" %d",ans[i]);printf("\n");exit(0);}else{for(int i=1;i<=N;++i){if(!flag[i] && x[ans[n-1]]!=x[i]){ans[n]=i;flag[i]=true;DFS(n+1);flag[i]=false;}}}}int main() {scanf("%d",&N);for(int i=1;i<=N;++i)scanf("%d",x+i);DFS(1);return 0;}
阅读全文
0 0
- codevs 2928 你缺什么
- CodeVS 2928 你缺什么 题解
- codevs 2928 你缺什么——搜索或模拟
- 你缺什么
- .NET 你还缺什么
- Codevs
- 你错过什么?
- 中国人, 你怕什么???
- 你爱我什么
- 告诉我,你需要什么?
- 管理学,你算什么
- 爱你,欠缺什么?
- 你凭什么创业?
- 什么让你与众不同?
- 你凭什么成功
- 你到底要什么?
- 你最后悔什么?
- 你最后悔什么
- 基于最小生成树的单连接算法
- springMVC实现过滤器
- 又一次血的教训:Protocol http not supported or disabled in libcurl
- 如何获取板子上独有的ID号EXYNOS4412/Imx6ul
- myeclipse中使用tomcat
- codevs 2928 你缺什么
- arm-linux-ld: error: Source object has EABI version 5, but target u-boot has EABI version 0
- ConterOS7 安装Redius
- #ifndef #define #endif
- mybatis传入多个参数
- List<T>转换为DataTable
- 杂谈:软件问价多少钱?
- 层序遍历二叉树
- vsftp修改存储目录