Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 투포인터
- SWEA
- 문제풀이
- math
- SQL
- 이분탐색
- 백준
- 문제해결
- 문자열
- 알고리즘
- 코딩테스트
- DP
- 시뮬레이션
- dfs
- greedy
- Java
- priorityqueue
- COS PRO
- 러닝일지
- binary search
- 자바
- 코테
- 건강
- 운동기록
- MySQL
- 프로그래머스
- oracle
- BOJ
- db
- BFS
Archives
- Today
- Total
슈콩
[BOJ] 백준 10942 팰린드롬? 본문
[문제]
https://www.acmicpc.net/problem/10942
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
int[] num = new int[n+1];
int[][] dp = new int[n+1][n+1];
dp[1][1] = 1;
st = new StringTokenizer(br.readLine());
for(int i=1;i<=n;i++) {
num[i] = Integer.parseInt(st.nextToken());
}
for(int i=2;i<=n;i++) {
dp[i][i] = 1;
if(num[i]==num[i-1]) dp[i-1][i] = 1;
}
for(int range=2;range<n;range++) {
for(int i=1;i<=n-range;i++) {
int s = i; int e = i+range;
if(num[s]==num[e] && dp[s+1][e-1]==1) dp[s][e] = 1;
}
}
int m = Integer.parseInt(br.readLine());
for(int t=0;t<m;t++) {
st = new StringTokenizer(br.readLine());
int s = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
sb.append(dp[s][e] + "\n");
}
System.out.println(sb);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 11057 오르막 수 (0) | 2025.08.22 |
|---|---|
| [BOJ] 백준 11053 가장 긴 증가하는 부분 수열 (0) | 2025.08.22 |
| [BOJ] 백준 10884 쉬운 계단 수 (2) | 2025.08.21 |
| [BOJ] 백준 1003 피보나치 함수 (0) | 2025.08.21 |
| [BOJ] 백준 7795 먹을 것인가 먹힐 것인가 (0) | 2025.08.20 |