#include <stdio.h>
#include <stdlib.h>
#define N 100
int value = 0;
int max = 0;
void dfs(int price[2][N],int start,int length){
if(start == length){
max = max > value ? max : value;
}
else{
int i;
for(i = start ; i < length ;i++){
if(!price[1][(i + length - 1)%length] &&
!price[1][(i+length+1)%length]){
value += price[0][i];
price[1][i] = 1;
dfs(price,i+1,length);
value -= price[0][i];
price[1][i] = 0;
}else{
dfs(price,i+1,length);
}
}
}
}
int main(void){
int price[2][N]={{1,2,4,9,2,3,4,5}};
dfs(price,0,8);
printf("%d",max);
return 0;
}
类似与这样的DFS吧 有错欢迎指出~~·