• 문제 링크
22971번: 증가하는 부분 수열의 개수
길이가 $N$인 수열 $A$가 주어진다. 수열의 $i$번째 원소($A_i$)로 끝나는 증가하는 부분 수열의 개수를 출력하는 프로그램을 작성하자. 단, 수가 너무 커질 수 있으니 $998\,244\,353$으로 나눈 나머지를
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int n = read();
int[] arr = new int[n], dp = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = read();
dp[i] = 1;
for (int j = 0; j < i; j++) if (arr[i] > arr[j]) dp[i] = (dp[i] + dp[j]) % 998244353;
}
for (int i : dp) sb.append(i).append(" ");
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 17291 새끼치기 - Dynamic Programming / Java (0) | 2023.09.28 |
---|---|
[백준] 4172 sqrt log sin - Dynamic Programming / Java (0) | 2023.09.27 |
[백준] 17216 가장 큰 감소 부분 수열 - Dynamic Programming / Java (0) | 2023.09.25 |
[백준] 28464 Potato - Greedy / Java (0) | 2023.09.24 |
[백준] 28353 고양이 카페 - Greedy / Java (0) | 2023.09.23 |
댓글