uva 729 - The Hamming Distance Problem
来源:互联网 发布:海信电视看网络电视 编辑:程序博客网 时间:2024/06/06 00:27
题意大概就是给出01串,让你输出全排列。
可以用next_permutation水过。
用dfs的时候注意添加0或者1的时候判断是否重复和注意不要重复递归。
#include<cstdio>#include<cstring>const int MAXN=20;int P[MAXN],A[MAXN];void dfs(int cur,int n){ if(cur==n){ for(int i=0;i<n;i++) printf("%d",A[i]); printf("\n"); } else for(int i=0;i<n;i++) if(!i || P[i]!=P[i-1]){ int c1=0,c2=0; for(int j=0;j<n;j++) if(P[i]==P[j]) c1++; for(int j=0;j<cur;j++) if(P[i]==A[j]) c2++; if(c2<c1){ A[cur]=P[i]; dfs(cur+1,n); } }}int main(){ //freopen("in.txt","r",stdin); int T; scanf("%d",&T); while(T--){ int N,H; memset(P,0,sizeof(P)); scanf("%d%d",&N,&H); for(int i=N-H;i<N;i++) P[i]=1; dfs(0,N); if(T) printf("\n"); } return 0;}
0 0
- UVa 729 The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- UVa 729: The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- uva - 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem 排列组合
- UVa 729 - The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVa-729-The Hamming Distance Problem
- UVA - 729 The Hamming Distance Problem
- [Java基础]
- [Java]java反射随笔
- 【转】个人最常用的Eclipse快捷键
- Android AdapterView 源码分析以及其相关回收机制的分析
- 网络判断的监听器
- uva 729 - The Hamming Distance Problem
- 【转载】Android使用Application总结
- SAS学习笔记(六)——关于数据格式的SAS函数
- ThreadPoolExecutor运转机制详解 - 走向架构师之路 - 博客频道 - CSDN.NET
- 对于android触摸事件模型的一些理解
- Selector中的各种状态详解
- 永久告别Android的背景选择器Selector!无需切很多图了!
- 程序结构
- hdu1080---Human Gene Functions