diff --git a/src/week6/BOJ14002/BOJ14002_V1.cpp b/src/week6/BOJ14002/BOJ14002_V1.cpp new file mode 100644 index 0000000..9f04da1 --- /dev/null +++ b/src/week6/BOJ14002/BOJ14002_V1.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; +int arr[1000], cnt[1000], ret=1, idx; +int _prev[1000]; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + fill(cnt, cnt+1000, 1); + fill(_prev, _prev+1000, -1); + int N; + cin >> N; + + for (int i=0; i> arr[i]; + } + + + for (int i=0; i arr[j] && cnt[j] + 1 > cnt[i]) { + cnt[i] = cnt[j] + 1; + _prev[i] = j; + if (ret < cnt[i]) { + ret = cnt[i]; + idx = i; + } + } + } + } + cout << ret << '\n'; + + stack stk; + while(true) { + if (idx == -1) break; + stk.push(arr[idx]); + idx = _prev[idx]; + } + + bool first = true; + while(stk.size()) { + if (!first) cout << ' '; + cout << stk.top(); + first = false; + stk.pop(); + } + cout << '\n'; + + + return 0; +}