본문 바로가기
프로그래머스

프로그래머스 pccp 모의고사 1-2 체육대회

by 콩순이냉장고 2024. 12. 1.

문제 URL : https://school.programmers.co.kr/learn/courses/15008/lessons/121684

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

문제 접근법 : 

전수 조사 문제이고 백트래킹을 이용해서 모든 경우의수를 구해 가장 최대값을 찾으면 되는문제입니다.

 

소스코드 :

#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> arr;
vector<int>check;
int n,m;
int dfs(int h){
    if(h>=m){
        return 0;
    }
    int res =0;
    for(int i=0;i<n;i++){
        if(check[i]==0){
            check[i]=1;
            res = max(res,dfs(h+1)+arr[i][h]);
            check[i]=0;
        }
    }
    return res;
}
int solution(vector<vector<int>> ability) {
    int answer = 0;
    n = ability.size();
    m = ability[0].size();
    arr = ability;
    check = vector<int>(n);
    return dfs(0);
}

 

궁금한점이나 모르는점 어떤 질문이든 댓글은 언제나 환영입니다.