inblog logo
|
LHS's Study Space
    알고리즘문제풀기C#

    [알고리즘 문제 풀기] 치킨치킨치킨(16439)

    C#
    lhs's avatar
    lhs
    Feb 16, 2025
    [알고리즘 문제 풀기] 치킨치킨치킨(16439)
    Contents
    1. 문제 풀이 아이디어2. 나의 정답 코드3. 정리
    www.acmicpc.net
    https://www.acmicpc.net/problem/16439
    notion image

    1. 문제 풀이 아이디어

    • 각 행에서 선택할 수 있는 세 개의 열 조합을 모두 확인하면서, 해당 열에서의 최댓값 합이 최대가 되는 경우를 찾아 문제를 해결할 수 있다.

    2. 나의 정답 코드

    using (StreamReader sr = new(Console.OpenStandardInput())) using (StreamWriter sw = new(Console.OpenStandardOutput())) { string[] split = sr.ReadLine().Split(); int n = int.Parse(split[0]); int m = int.Parse(split[1]); int[][] a = new int[n][]; for (int i = 0; i < n; i++) { a[i] = Array.ConvertAll(sr.ReadLine().Split(), int.Parse); } int result = 0; for (int i = 0; i < m - 2; i++) { for (int j = i; j < m - 1; j++) { for (int k = j; k < m; k++) { int sum = 0; for (int l = 0; l < n; l++) { sum += Math.Max(Math.Max(a[l][i], a[l][j]), a[l][k]); } result = Math.Max(result, sum); } } } sw.Write(result); }

    3. 정리

    • 세 개의 열을 선택하는 모든 조합을 탐색하며, 각 행에서 선택한 열들 중 최댓값을 구한다.
    • 모든 행의 최댓값을 합산한 결과 중 최댓값을 result에 저장하여 출력해 문제를 해결한다.
    Share article

    LHS's Study Space

    RSS·Powered by Inblog