-
[C++] ์ผ์ฑ 4012. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์๋ฆฌ์ฌ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:20728x90
(30๋ถ) ์ฌ๋ฃ๋ฅผ ๋ถ๋ฐฐํ๋ ๊ณผ์ ์ ๋ ๊น๋ํ๊ฒ ์ง๊ณ ์ถ์๋ฐ ์์ด๋์ด๊ฐ ๋ ์ค๋ฅด์ง ์์..
#include<iostream> #include<vector> #include<stdlib.h> using namespace std; int synergy[16][16]; int minDifference; int calSynergy(vector<int> food){ int totalSynergy = 0; for(int i=0; i<food.size(); i++){ for(int j=0; j<food.size(); j++){ totalSynergy += synergy[food[i]][food[j]]; } } return totalSynergy; } void shareIndex(vector<int> A, vector<int> B, int N, int currentIndex){ if(currentIndex == N){ int difference = abs(calSynergy(A) - calSynergy(B)); if(minDifference > difference) minDifference = difference; return; } if(A.size() < N/2){ A.push_back(currentIndex); shareIndex(A, B, N, currentIndex + 1); A.pop_back(); } if(B.size() < N/2){ B.push_back(currentIndex); shareIndex(A, B, N, currentIndex + 1); B.pop_back(); } } int main(){ int T; cin >> T; for(int t=1; t<=T; t++){ int N; cin >> N; for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ cin >> synergy[i][j]; } } minDifference = 9999999; vector<int> A; vector<int> B; shareIndex(A, B, N, 0); cout << "#" << t << " " << minDifference << endl; } return 0; }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ์ผ์ฑ 2105. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋์ ํธ ์นดํ (0) 2020.10.27 [C++] ์ผ์ฑ 1767. [SW Test ์ํ๋ฌธ์ ] ํ๋ก์ธ์ ์ฐ๊ฒฐํ๊ธฐ (0) 2020.10.27 [C++] ์ผ์ฑ 1249. [S/W ๋ฌธ์ ํด๊ฒฐ ์์ฉ] 4์ผ์ฐจ - ๋ณด๊ธ๋ก (0) 2020.10.27 [C++] [ํ๋ก๊ทธ๋๋จธ์ค 2020 KAKAO] ๊ธฐ๋ฅ๊ณผ ๋ณด ์ค์น (0) 2020.10.27 [C++] ์ผ์ฑ 2477. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ฐจ๋ ์ ๋น์ (0) 2020.10.27