※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6193번 문제인 Hungry Cows이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6193
6193번: Hungry Cows
Each of Farmer John's N (1 <= N <= 5,000) cows has a unique positive integer brand that fits nicely into 32 signed bits. He wishes the cows would line up in numerical order for feeding, but they never cooperate. To encourage good behavior, he allows a cow
www.acmicpc.net
이 문제는 주어지는 수열의 LIS(Longest Increasing Subsequence)의 길이를 구하는 문제이다. LIS 문제의 해법을 이용해 문제를 해결하자.
N의 크기가 작으므로
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll arr[5000];
int dp[5000];
int ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
for (int j = 0; j < i; j++) {
if (arr[j] < arr[i]) dp[i] = max(dp[i], dp[j]);
}
dp[i]++;
ans = max(ans, dp[i]);
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 2992 // C++] 크면서 작은 수 (1) | 2024.01.15 |
---|---|
[BOJ 2780 // C++] 비밀번호 (0) | 2024.01.14 |
[BOJ 6192 // C++] Cow Pie Treasures (0) | 2024.01.12 |
[BOJ 6191 // C++] Cows on Skates (0) | 2024.01.11 |
[BOJ 25399 // C++] 라그랑주님 수학에는 뺄셈도 있어요 (0) | 2024.01.10 |