[BOJ] 16942 문자열 접기

Time Lapse :40min 20sec

16942.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
string s;
short ans = 1, len, dp[1001];
short dpf(int n) {
if(dp[n] != -1) return dp[n];
dp[n] = 1;
for(int i = n + 1; i < len; i += 2)
if(s[n] == s[i])
dp[n] = max(dp[n], (short)(dpf(i) + 1));
return dp[n];
}
int main(void) {
cin >> s;
memset(dp, -1, sizeof(dp));
len = s.length();
for(int i = 0; i < len; ++i)
ans = max(dpf(i), ans);
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/25/PS/BOJ/16942/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.