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.09.12 - [BOJ] 1182. 부분수열의 합 #171

Closed
suhyunsim opened this issue Sep 12, 2021 · 0 comments
Closed

21.09.12 - [BOJ] 1182. 부분수열의 합 #171

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Sep 12, 2021

문제

핵심 아이디어

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int ans = go(a, s, 0, 0);
        if (s == 0) ans -= 1;
        System.out.println(ans);
    }

    private static int go(int[] a, int s, int i, int sum) {
        if (i == a.length) {
            if (sum == s) return 1;
            else return 0;
        }
        return go(a, s, i + 1, sum + a[i]) + go(a, s, i + 1, sum);
    }
}
@suhyunsim suhyunsim self-assigned this Sep 12, 2021
@suhyunsim suhyunsim added 브루트포스 완전탐색 실버 BOJ - 실버 labels Sep 13, 2021
@suhyunsim suhyunsim added this to the 9월 2주 차 milestone Sep 13, 2021
@suhyunsim suhyunsim added the 성공 맞은 문제 label Sep 13, 2021
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