331 - Mapping the Swaps
来源:互联网 发布:北大青鸟消防编程公式 编辑:程序博客网 时间:2024/04/30 13:28
描述:这道题说是冒泡排序,其实和图里面的路差不多,就是从一个地方走到另一个地方有多少种方法,只不过这道题不能出现重复排数,也就是说不能A1与A2交换后接着再次A1与A2交换的情况,逆序数可用可不用,根据自己的思路就可以#include <cstdio>int count,n,m[6],j,Time;void dfs(int cur){ if(cur>=Time) { count++; return; } for(int i=1; i<n; i++) if(m[i-1]>m[i]) { int temp=m[i-1]; m[i-1]=m[i]; m[i]=temp; dfs(cur+1); m[i]=m[i-1]; m[i-1]=temp; }}int main(){#ifndef ONLINE_JUDGE freopen("a.txt","r",stdin);#endif j=0; while(scanf("%d",&n)!=EOF) if(!n) break; else { Time=count=0; for(int i=0; i<n; i++) scanf("%d",&m[i]); for(int i=0; i<n; i++) for(int k=i+1; k<n; k++) if(m[k]<m[i]) Time++; if(Time) dfs(0); printf("There are %d swap maps for input data set %d.\n",count,++j); } return 0;}
- 331--Mapping the Swaps
- 331 - Mapping the Swaps
- uva 331 Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVA 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVA 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- UVa:331 Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVa 331Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- [Matlab]基础教程学习笔记(一):基础和设置和矩阵教程
- 求四个数的最大公约数
- 51单片机流水灯入门(理解IO口的组操作)
- 阿里巴巴分布式服务框架 Dubbo 团队成员梁飞专访
- 字符串移位包含问题研究
- 331 - Mapping the Swaps
- 最完整的htaccess文件用法
- JavaScript 高级语法(function(){})() 语法介绍
- (复习)android 调用系统相机 图库 裁剪-图片上传-客服端-服务器
- jkkk
- Download android source code occur "server certificate verification failed "
- HTTP 设置超时
- 甘肃散记417
- itext基础学习