Uva--331(暴力)
2014-07-15 22:42:55
题意&思路:不说啥了,感冒了,脑子一团粥。
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 5 int n,cnt,s[10]; 6 7 bool Isorder(){ 8 for(int i = 0; i < n - 1; ++i) 9 if(s[i] > s[i + 1]) 10 return false; 11 return true; 12 } 13 14 void Dfs(){ 15 if(Isorder()){ 16 ++cnt; 17 return; 18 } 19 int tem; 20 for(int i = 0; i < n - 1; ++i){ 21 if(s[i] > s[i + 1]){ 22 tem = s[i]; s[i] = s[i + 1]; s[i + 1] = tem; 23 Dfs(); 24 tem = s[i]; s[i] = s[i + 1]; s[i + 1] = tem; 25 } 26 } 27 } 28 29 int main(){ 30 int Case = 0; 31 while(scanf("%d",&n) == 1 && n){ 32 for(int i = 0; i < n; ++i) 33 scanf("%d",&s[i]); 34 cnt = 0; 35 if(!Isorder()) 36 Dfs(); 37 printf("There are %d swap maps for input data set %d.\n",cnt,++Case); 38 } 39 return 0; 40 }