baekjoon 20260308
This commit is contained in:
parent
2571466cbc
commit
e0fc579755
8
code_study/Baekjoon/python/11365.py
Normal file
8
code_study/Baekjoon/python/11365.py
Normal file
@ -0,0 +1,8 @@
|
||||
import sys
|
||||
input = sys.stdin.readline
|
||||
res = []
|
||||
|
||||
while (s := input().rstrip()) != "END" :
|
||||
res.append(s[::-1])
|
||||
|
||||
print("\n".join(res))
|
||||
37
code_study/Baekjoon/ts/1509.ts
Normal file
37
code_study/Baekjoon/ts/1509.ts
Normal file
@ -0,0 +1,37 @@
|
||||
export {};
|
||||
const str = require("fs").readFileSync(0).toString().trim();
|
||||
const len: number = str.length
|
||||
|
||||
let isPalindrom: boolean[][] = Array.from({length : len}, () => new Array(len).fill(false));
|
||||
for(let i = 0; i < len; i++) {
|
||||
isPalindrom[i][i] = true;
|
||||
if(i != len - 1 && str[i] === str[i+1]) {
|
||||
isPalindrom[i][i+1] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for(let l = 3; l <= len; l++) {
|
||||
for(let start = 0; start <= len - l; start++) {
|
||||
const end: number = start + l - 1;
|
||||
|
||||
if(str[start] === str[end] && isPalindrom[start+1][end-1]) {
|
||||
isPalindrom[start][end] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let dp: number[] = new Array(len).fill(len);
|
||||
|
||||
for(let end = 0; end < len; end++) {
|
||||
for(let start = 0; start <= end; start++) {
|
||||
if(isPalindrom[start][end]) {
|
||||
if(start === 0) dp[end] = 1;
|
||||
else {
|
||||
dp[end] = Math.min(dp[end], dp[start - 1] + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(dp[len-1]);
|
||||
Loading…
x
Reference in New Issue
Block a user