Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.10.09 - [BOJ] 16198. 에너지 모으기 #176

Closed
suhyunsim opened this issue Oct 9, 2021 · 0 comments
Closed

21.10.09 - [BOJ] 16198. 에너지 모으기 #176

suhyunsim opened this issue Oct 9, 2021 · 0 comments
Assignees
Labels
브루트포스 완전탐색 성공 맞은 문제 실버 BOJ - 실버 재귀

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q16198;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        System.out.println(go(list));
    }

    private static int go(List<Integer> list) {
        int k = list.size();
        if (k == 2) return 0;
        int ans = 0;
        for (int i = 1;  i < k - 1; i++) {
            int energy = list.get(i - 1) * list.get(i + 1);
            List<Integer> left = new ArrayList<>(list);
            left.remove(i);
            energy += go(left);
            if (ans < energy) {
                ans = energy;
            }
        }
        return ans;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
브루트포스 완전탐색 성공 맞은 문제 실버 BOJ - 실버 재귀
Projects
None yet
Development

No branches or pull requests

1 participant