[백준] 3980번 선발 명단 (C++)

2025. 9. 30. 19:21·Algorithm
728x90

https://www.acmicpc.net/problem/3980

 

 

이 문제는 11명의 선수가 주어지고 선수당 각자의 포지션에 대한 능력치가 존재할때 그 합이 최대인 것을 구하는 문제이다.

 

선수는 최대 11명 고정으로 11명을 일렬로 나열하는 경우가 최악이 되지만 이때 능력치가 0인 경우는 무시하면 이것보다 훨씬 더 적게 나오기 때문에 모든 경우를 찾아보며 최댓값을 갱신해주면 된다.

 

N의 크기를 보면 쉽게 알고리즘을 생각할 수 있는 문제였다.

 

 

정답코드

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define endl "\n"
#define MAX 1e9

struct coordinate {
    int x;
    int y;
    int r;
};

int dx[] = {-1, 1, 0, 0, 1, -1, -1, 1};
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int T, answer;
bool visited[11];

void bt(int x, int cnt, vector<vector<int>> &graph, int val) {
    if(cnt == 11) {
        answer = max(answer, val);
        return;
    }

    for(int i = 0; i < 11; i++) {
        if(graph[x][i] > 0 && !visited[i]) {
            visited[i] = true;
            bt(x+1, cnt+1, graph, val + graph[x][i]);
            visited[i] = false;
        }
    }
}

void solve(vector<vector<int>> &graph) {
    bt(0, 0, graph, 0);

    cout << answer << endl;
}

void input() {
    cin >> T;

    while(T--) {
        answer = 0;
        vector<vector<int>> v(11, vector<int>(11, 0));

        for(auto &it : v) {
            for(auto &iter : it) {
                cin >> iter;
            }
        }

        solve(v);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    input();
}

 

 

728x90
저작자표시 (새창열림)

'Algorithm' 카테고리의 다른 글

[백준] 13905번 세부 (C++)  (0) 2025.10.02
[백준] 13325번 이진 트리 (C++)  (0) 2025.10.01
[백준] 12033번 김인천씨의 식료품가게 (Small) (C++)  (0) 2025.09.29
[백준] 14607번 피자 (Large) (C++)  (0) 2025.09.28
[백준] 1939번 중량제한 (C++)  (0) 2025.09.27
'Algorithm' 카테고리의 다른 글
  • [백준] 13905번 세부 (C++)
  • [백준] 13325번 이진 트리 (C++)
  • [백준] 12033번 김인천씨의 식료품가게 (Small) (C++)
  • [백준] 14607번 피자 (Large) (C++)
쿨쿨.
쿨쿨.
  • 쿨쿨.
    All of the life
    쿨쿨.
  • 전체
    오늘
    어제
    • 분류 전체보기 (281) N
      • Programming (49) N
        • C, C++ (18)
        • Python (6)
        • Java (1)
        • HTML,CSS,JS (3)
        • SQL(DB) (13)
        • SpringBoot (5) N
        • Android (2)
        • CI,CD (1)
      • Algorithm (173)
        • Review (4)
      • Security (14)
        • WebHacking (3)
        • Websecurity (11)
      • OS (19)
        • Linux (12)
        • Mac os (2)
      • 머신러닝 (1)
      • CS(Computer Science) (12)
        • 컴퓨터 네트워크 (3)
        • 컴퓨터 구조 (1)
        • 인공지능 (8)
      • Docker (1)
      • Dev Book Review (3)
        • Clean Code (1)
        • Effective Java (0)
        • Real MySQL (2)
      • SWM (1)
      • Review (6)
      • AWS (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    우선순위큐
    재귀
    다익스트라
    에라토스테네스의 체
    백준
    DFS
    그리디
    구현
    시뮬레이션
    브루트포스
    그래프 이론
    linux
    누적합
    코딩
    우선순위 큐
    c언어
    다이나믹 프로그래밍
    wargame
    비트마스킹
    DP
    이분탐색
    Bandit
    WebSecurity
    BFS
    투포인터
    Leviathan
    백트래킹
    정렬
    깊이우선탐색
    트리
  • 최근 댓글

  • 최근 글

  • 250x250
  • hELLO· Designed By정상우.v4.10.6
쿨쿨.
[백준] 3980번 선발 명단 (C++)
상단으로

티스토리툴바