1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<cstdio> #include<cstdlib> int n,maxVal=0; int arr[10]; int ans[10]; bool check[10]; void func(int cnt) { if(cnt==n){ int temp=0; for(int i=0; i<n-1; i++) temp+=std::abs(ans[i]-ans[i+1]); maxVal=maxVal>temp?maxVal:temp; } for(int i=0; i<n; i++) { if(!check[i]) { check[i]=true; ans[cnt]=arr[i]; func(cnt+1); check[i]=false; } } } int main(void) { scanf("%d", &n); for(int i=0; i<n; i++) scanf("%d", &arr[i]); func(0); printf("%d", maxVal); return 0; } | cs |
'백준 2 > 완전탐색' 카테고리의 다른 글
| [백준 10971] 외판원 순회2 (0) | 2020.12.07 |
|---|---|
| [백준 2309] 일곱 난쟁이 (C++/Python) (0) | 2020.12.07 |
| [백준 10974] 모든 순열 (0) | 2020.12.07 |
| [백준 17141] 연구소 2 (0) | 2020.12.07 |
| [백준 1182] 부분수열의 합 (C++/Python) (0) | 2020.12.07 |