반응형
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
- 코딩테스트
- 개발
- bigdata engineering
- BigData
- Apache Kafka
- 코테
- Trino
- 코딩
- 용인맛집
- bigdata engineer
- 맛집
- apache iceberg
- Iceberg
- 자바
- 삼성역맛집
- Kafka
- Data Engineer
- 여행
- 코엑스맛집
- pyspark
- 알고리즘
- Spark
- HIVE
- 백준
- Data Engineering
- 영어
- java
- 프로그래머스
- hadoop
- 코엑스
Archives
- Today
- Total
지구정복
[DP] 백준 - 1,2,3 더하기 본문
728x90
반응형
-문제
https://www.acmicpc.net/problem/9095
9095번: 1, 2, 3 더하기
각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다.
www.acmicpc.net
-자바
package dp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Plus123_1 {
private static BufferedWriter bw =
new BufferedWriter( new OutputStreamWriter(System.out));
private static int t; //테스트케이스 개수
private static int n; //주어지는 정수
private static int[] arr; //정수 n이 만들어지는 개수가 담길 배열
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
t = Integer.parseInt( br.readLine() );
arr = new int[11];
arr[1] = 1;
arr[2] = 2;
arr[3] = 4;
for( int i=0; i<t; i++ ) {
n = Integer.parseInt( br.readLine() );
for( int j=4; j<=n; j++ ) {
arr[j] = arr[j-1] + arr[j-2] + arr[j-3];
}
bw.write( arr[n] + "\n" );
bw.flush();
}
bw.close();
br.close();
}
}
-파이썬
t = int( input() )
arr = [0] * 11
for i in range(t):
n = int( input() )
arr[1] = 1
arr[2] = 2
arr[3] = 4
for j in range(4, n+1):
arr[j] = arr[j-1] + arr[j-2] + arr[j-3]
print( arr[n] )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[DP] 이코테 - 개미전사 (1) | 2021.07.12 |
---|---|
[DP] 백준 - 계단오르기 (0) | 2021.07.11 |
[DP] 이코테 - 1이 될 때까지 (0) | 2021.07.10 |
[BFS, DFS] 백준 - 단지번호붙이기 (0) | 2021.07.09 |
[수학, 구현] 백준 - 셀프넘버 (0) | 2021.07.09 |
Comments