baekjoon 20260402
This commit is contained in:
parent
2aa4c9cd8f
commit
9f82e4e35b
46
code_study/Baekjoon/c/1509.c
Normal file
46
code_study/Baekjoon/c/1509.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
bool isPalindrome[2500][2500];
|
||||
char str[2501];
|
||||
int dp[2500];
|
||||
|
||||
int main() {
|
||||
scanf("%s", str);
|
||||
int length = strlen(str);
|
||||
|
||||
isPalindrome[0][0] = true;
|
||||
for(int i=1; i<length; i++) {
|
||||
isPalindrome[i][i] = true;
|
||||
|
||||
if(str[i-1] == str[i]) {
|
||||
isPalindrome[i-1][i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for(int len = 3; len <= length; len++) {
|
||||
for(int start = 0; start <= length - len; start++) {
|
||||
int end = start + len - 1;
|
||||
|
||||
if(str[start] == str[end] && isPalindrome[start+1][end-1]) {
|
||||
isPalindrome[start][end] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<length; i++) dp[i] = length;
|
||||
|
||||
for(int end=0; end<length; end++) {
|
||||
for(int start=0; start <=end; start++) {
|
||||
if(isPalindrome[start][end]) {
|
||||
if(start == 0) dp[end] = 1;
|
||||
else dp[end] = (dp[end] < dp[start-1] + 1) ? dp[end] : dp[start-1] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", dp[length-1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
code_study/Baekjoon/python/4435.py
Normal file
1
code_study/Baekjoon/python/4435.py
Normal file
@ -0,0 +1 @@
|
||||
print("\n".join([f"Battle {i+1}: {'Good triumphs over Evil' if (gan := sum(a*b for a,b in zip([1,2,3,3,4,10], map(int, input().split())))) > (sau := sum(a*b for a,b in zip([1,2,2,2,3,5,10], map(int, input().split())))) else 'Evil eradicates all trace of Good' if gan < sau else 'No victor on this battle field'}" for i in range(int(input()))]))
|
||||
Loading…
x
Reference in New Issue
Block a user