From 390180e37c9ececaf226a662f2fef8a3def940c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AC=B8=ED=98=95?= <74577714+alirz-pixel@users.noreply.github.com> Date: Tue, 20 Jan 2026 00:12:54 +0900 Subject: [PATCH] =?UTF-8?q?260119=20:=20[BOJ=201029]=20=EA=B7=B8=EB=A6=BC?= =?UTF-8?q?=20=EA=B5=90=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _munhyeong/1029.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 _munhyeong/1029.cpp diff --git a/_munhyeong/1029.cpp b/_munhyeong/1029.cpp new file mode 100644 index 00000000..ee246d0e --- /dev/null +++ b/_munhyeong/1029.cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +int recursive(vector> &price, vector>> &dp, int visited, int artist, int boundary) { + int& ret = dp[visited][artist][boundary]; + if (ret != -1) + return ret; + + ret = 0; + for (int i = 1; i < price.size(); i++) { + if (!(visited & (1 << i)) && price[artist][i] >= boundary) { + int next_visited = visited | (1 << i); + ret = max(ret, recursive(price, dp, next_visited, i, price[artist][i]) + 1); + } + } + + return ret; +} + +int main() { + int N; + cin >> N; + + vector> price(N, vector(N)); + for (int i = 0; i < N; i++) { + string input; + cin >> input; + + for (int x = 0; x < N; x++) + price[i][x] = input[x] - '0'; + } + + vector>> dp(1 << N, vector>(N, vector(10, -1))); + recursive(price, dp, 1, 0, 0); + + cout << dp[1][0][0] + 1; + + return 0; +}