BOJ::1965 상자넣기
https://www.acmicpc.net/problem/1965
다이나믹 프로그래밍 문제들 중 기본이 아닐까 싶다.
<JAVA>
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 32 33 34 35 36 37 38 39 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int box[]=new int[1001]; static int d[]=new int[1001]; public static void main(String args[]) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); for(int i = 1 ; i <= n; i++){ box[i]=Integer.parseInt(st.nextToken()); } int max =0; for(int i = 1 ; i <= n ; i++){ d[i]=1; for(int j = 1 ; j < i; j++){ if(box[i]>box[j]){ if(d[i] < d[j]+1){ d[i]=d[j]+1; } } } if(d[i]> max){ max = d[i]; } } System.out.println(max); } } | cs |
<C++>
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 | #include <iostream> using namespace std; int n; int box[1001]; int d[1001]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> box[i]; } int max = 0; for (int i = 1; i <= n; i++) { d[i] = 1; for (int j = 1; j < i; j++) { if (box[i] > box[j]) { if (d[i] < d[j] + 1) { d[i] = d[j] + 1; } } } if (max < d[i]) { max = d[i]; } } cout << max << endl; } | cs |
'BOJ::문제풀이' 카테고리의 다른 글
2096 내려가기 (0) | 2018.01.01 |
---|---|
1987 알파벳 (0) | 2018.01.01 |
1934 최소공배수 (0) | 2018.01.01 |
1932 숫자삼각형 (0) | 2018.01.01 |
1929 소수 구하기 (0) | 2018.01.01 |