https://school.programmers.co.kr/learn/courses/15008/lessons/121684
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก, ์ฑ์ฉ๊น์ง Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
ํ๋ก๊ทธ๋๋จธ์ค PCCP ๋ชจ์๊ณ ์ฌ 1ํ - 2๋ฒ
์์์๊ฐ ์ฝ 23๋ถ
์์ด(permutation) ํน์ dfs/์ฌ๊ท ์ ํ, ์ถ์ ๋์ด๋๋ level 2-3
๋ด๊ฐ C++์ ์ข์ํ๋ ์ด์ ,,,
์์ด๊ฐ์ ๊ธฐ๋ณธ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ ๋ถ๋ด์ ์ค์ฌ์ฃผ๋ ํ์ค ํจ์๊ฐ ํ๋ถํ๋ค!!
ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค <algorithm> next_permutation ํจ์๋ฅผ ์ฌ์ฉํด์ ํด๊ฒฐํ์๋ค.
โ ๏ธ ์์ด ํจ์ ์ฌ์ฉ์์๋ ๋ฐ๋์ ์ ๋ ฌ ํ, do~while ๋ฐ๋ณต๋ฌธ์ผ๋ก ์จ์ค์ผ ํ๋ค.
๊ทธ๋ฆฌ๊ณ ์ด ๋ฌธ์ ์์๋ ability ๋ฒกํฐ๋ฅผ reverseํด์ค์ผ ํจ (์ด๋์ข ๋ชฉ ๊ธฐ์ค์ผ๋ก ์์ด ์ฒ๋ฆฌํ๊ธฐ ์ํด์)
๋์ ํ์ด
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int solution(vector<vector<int>> ability) {
int answer = 0;
// ์ต๋๊ฐ, ๊ทธ๋ฆฌ๋? ๊ฐ ์ข
๋ชฉ๋ณ๋ก ์์ ๋ค๋ฅด๊ฒ
int students = ability.size();
int sports = ability[0].size();
vector<vector<int>> reverse;
// ์์ด์ ์ํด ๋ฒกํฐ ๋ค์ง๊ธฐ
for(int i=0; i<sports; ++i){
vector<int> v;
for(int j=0; j<students; ++j) v.push_back(ability[j][i]);
reverse.push_back(v);
}
// ์์ด ํ์ฉํด์ ๋ชจ๋ ๊ฒฝ์ฐ์ ์ ํ์
sort(reverse.begin(), reverse.end());
do{
vector<vector<int>> abt = reverse;
int maxSum = 0;
for(int i=0; i<sports; ++i){
int maxAb = 0;
int maxIdx = 0;
for(int j=0; j<students; ++j){
if(maxAb < abt[i][j]) {
maxAb = abt[i][j];
maxIdx = j;
}
}
maxSum += maxAb;
for(int k=0; k<sports; ++k){
abt[k][maxIdx] = 0;
}
}
if(answer < maxSum) answer = maxSum;
}while(next_permutation(reverse.begin(), reverse.end()));
return answer;
}
๋ชจ์๊ณ ์ฌ 1ํ๋ 3๋ฒ ์ ์ธํ๊ณ ๋ค ํด๊ฒฐํ๋ค.
3๋ฒ์.....์ํ ๋ฌธ์ ์ธ๋ฐ ๋ชป ํ๊ฒ ๋ค ใ ใ ํํธ ์ป์ด์ผ ํ ๋ฏ
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++/PGS] [PCCP ๊ธฐ์ถ๋ฌธ์ ] 1๋ฒ - ๋ถ๋ ๊ฐ๊ธฐ (0) | 2025.05.02 |
---|---|
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 3๋ฒ - ์ ์ ๋ฒ์น ๐คฏ (0) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 1๋ฒ - ์ธํจ์ด ์ํ๋ฒณ (0) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #1] 4๋ฒ - ์ด์์ฒด์ (0) | 2025.05.02 |
[C++/PGS] [PCCP ๋ชจ์๊ณ ์ฌ #2] 4๋ฒ - ๋ณด๋ฌผ์ง๋ (0) | 2025.05.01 |