标签:ash pre scanf printf print else 训练 turn mda
//摆动序列 #include<stdio.h> int k,num; int data[22],book[22]; void dfs(int t){ if(t>1){ if(t==2) num++; else{ int flag = 1; for(int i=t-1;i>=2;i--){ //条件4 if((data[i-1]-data[i-2])*(data[i] - data[i-2]) >=0 ){ flag = 0; break; } if(flag == 1) num++; else return; } } } for(int i=1;i<=k;i++){ if(book[i] == 0){ data[t] = i; //将1——k保存在data[]数组中 book[i] = 1; dfs(t+1); book[i] = 0; } } return; } int main(){ //输入k num=0; scanf("%d",&k); dfs(0); printf("%d",num); return 0; }
标签:ash pre scanf printf print else 训练 turn mda
原文地址:https://www.cnblogs.com/Hqx-curiosity/p/12234951.html