반응형
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
- Apache Kafka
- Data Engineer
- bigdata engineering
- bigdata engineer
- 백준
- 자바
- Trino
- 삼성역맛집
- 코엑스맛집
- 여행
- java
- apache iceberg
- Spark
- 알고리즘
- Kafka
- 프로그래머스
- 영어
- Data Engineering
- Iceberg
- 코테
- HIVE
- 맛집
- hadoop
- 코딩테스트
- 용인맛집
- BigData
- 코엑스
- 개발
- 코딩
- pyspark
Archives
- Today
- Total
지구정복
[DP] 백준 - 카드 구매하기 본문
728x90
반응형
-자바
package dp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BuyingCard1 {
private static int n;
private static int[] p;
private static int[] d;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt( br.readLine() );
p = new int[n+1]; //카드팩의 가격
d = new int[n+1]; //dp배열
StringTokenizer st = new StringTokenizer( br.readLine() );
for( int i=1; i<=n; i++ ) p[i] = Integer.parseInt( st.nextToken() );
d[0] = p[0];
for( int i=1; i<=n; i++ ) {
for( int j=1; j<=i; j++ ) {
d[i] = Math.max( d[i] ,d[i-j]+p[j] );
}
}
System.out.println( d[n] );
}
}
-파이썬
n = int( input() )
p = [0] + list( map( int, input().split() ) )
d = [0] * (n+1)
for i in range( 1, n+1 ):
for j in range( 1, i+1 ):
d[i] = max( d[i], d[i-j]+p[j] )
print( d[n] )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[DP] 백준 - 카드 구매하기 2 (0) | 2021.07.13 |
---|---|
[DP] 백준 - 2Xn 타일링 (0) | 2021.07.13 |
[DP] 이코테 - 호율적인 화폐구성 (0) | 2021.07.13 |
[DP] 이코테 - 바닥공사 (0) | 2021.07.12 |
[DP] 이코테 - 개미전사 (1) | 2021.07.12 |
Comments