From accd7fe48fe40a9508380b5fe42f2e0a93ae42c6 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 29 Jun 2026 17:45:41 +0900 Subject: [PATCH 1/2] =?UTF-8?q?1285=20:=20=EB=8F=99=EC=A0=84=20=EB=92=A4?= =?UTF-8?q?=EC=A7=91=EA=B8=B0=20v1=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week4/BOJ1285/BOJ1285_V1.cpp | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/week4/BOJ1285/BOJ1285_V1.cpp diff --git a/src/week4/BOJ1285/BOJ1285_V1.cpp b/src/week4/BOJ1285/BOJ1285_V1.cpp new file mode 100644 index 0000000..7799ee1 --- /dev/null +++ b/src/week4/BOJ1285/BOJ1285_V1.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; +bool bitmap[20][20]; +int N; +int ret = INT_MAX; +int calculate() { + int cnt = 0; + for (int i = 0; i < N; i++) { + int t=0; + for (int j = 0; j < N; j++) { + if (bitmap[j][i]) t++; + } + cnt += min(t, N-t); + } + return cnt; +} +void flip(int row) { + for (int i = 0; i < N; i++) { + bitmap[row][i] = !bitmap[row][i]; + } +} +void solve(int st) { + if (st == N) { + ret = min(ret, calculate()); + return; + } + solve(st+1); + flip(st); + solve(st+1); + flip(st); +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + for (int i=0; i> s; + for (int j=0; j Date: Mon, 29 Jun 2026 17:58:17 +0900 Subject: [PATCH 2/2] =?UTF-8?q?1285=20:=20=EB=8F=99=EC=A0=84=20=EB=92=A4?= =?UTF-8?q?=EC=A7=91=EA=B8=B0=20v2=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week4/BOJ1285/BOJ1285_V2.cpp | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/week4/BOJ1285/BOJ1285_V2.cpp diff --git a/src/week4/BOJ1285/BOJ1285_V2.cpp b/src/week4/BOJ1285/BOJ1285_V2.cpp new file mode 100644 index 0000000..39d97c9 --- /dev/null +++ b/src/week4/BOJ1285/BOJ1285_V2.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; +int N; +int inp[21]; +int ret = INT_MAX; +int calculate() { + int sum = 0; + for (int i=1; i<=(1 << (N-1)); i*=2) { + int cnt = 0; + for (int j=1; j<=N; j++) { + if (inp[j] & i) cnt++; + } + sum += min(cnt, N-cnt); + } + return sum; +} +void solve(int st) { + if (st == N+1) { + ret = min(ret, calculate()); + return; + } + + solve(st+1); + inp[st] = ~inp[st]; + solve(st+1); + inp[st] = ~inp[st]; +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + + for (int i = 1; i <= N; i++) { + string s; + cin >> s; + int tmp = 1; + for (int j=0; j