Created
March 26, 2020 15:30
-
-
Save niklasjang/a5db9d774aad4b4e374902f42751c097 to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][10819][차이를최대로]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| int n=0; | |
| int input[10]; | |
| int arr[10]; | |
| int ans =0; | |
| bool visited[10]; | |
| void calculate(void){ | |
| int temp = 0; | |
| for(int i=0; i< n-1; i++){ | |
| temp += abs(arr[i] - arr[i+1]); | |
| } | |
| ans = ans < temp ? temp : ans; | |
| return; | |
| } | |
| void recur(int depth){ | |
| if(depth == n){ | |
| calculate(); | |
| return; | |
| } | |
| for(int i=0; i<n; i++){ | |
| if(visited[i]) continue; | |
| arr[depth] = input[i]; | |
| visited[i] = true; | |
| recur(depth+1); | |
| visited[i] = false; | |
| } | |
| } | |
| int main(void){ | |
| cin>> n; | |
| for(int i=0; i<n; i++){ | |
| cin>> input[i]; | |
| } | |
| recur(0); | |
| cout<< ans<<'\n'; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment