본문 바로가기

C++

(226)
[BOJ] 11055번 가장 큰 증가 부분 수열 (C++) https://www.acmicpc.net/problem/11055 11055번: 가장 큰 증가 부분 수열 수열 A가 주어졌을 때, 그 수열의 증가 부분 수열 중에서 합이 가장 큰 것을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {1, 100, 2, 50, 60, 3, 5, 6, 7, 8} 인 경우에 합이 가장 큰 증가 부분 수 www.acmicpc.net #include #include #include using namespace std; int main() { int n; cin >> n; vector arr(n); vector dp(n); for(int i = 0; i > arr[i]; } int answer = 0; for(int y = 0; y < n; ..
[BOJ] 11053번 가장 긴 증가하는 부분 수열 (C++) https://www.acmicpc.net/problem/11053 11053번: 가장 긴 증가하는 부분 수열 수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이 www.acmicpc.net #include #include #include using namespace std; int main() { int n; cin >> n; vector arr(n, 0); vector dp(n, 1); for (int x = 0; x > arr[x]; } int answer = 0; for..
[BOJ] 14567번 선수과목 (Prerequisite) (C++) https://www.acmicpc.net/problem/14567 14567번: 선수과목 (Prerequisite) 3개의 과목이 있고, 2번 과목을 이수하기 위해서는 1번 과목을 이수해야 하고, 3번 과목을 이수하기 위해서는 2번 과목을 이수해야 한다. www.acmicpc.net #include #include #include #include using namespace std; int n, m, indegree[1001]; vector a[1001]; void topologySort(){ int result[1001]; queue q; for(int i = 1; i m; for(int i = 0; i > x >> y; a[x].push_back(y);..
[BOJ] 1149번 RGB거리 (C++) https://www.acmicpc.net/problem/1149 1149번: RGB거리 첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. 집을 칠하는 비용은 1,000보다 작거나 www.acmicpc.net #include #include using namespace std; int house[1001][3]; int main() { int n; cin >> n; int r, g, b; for(int i = 1; i > r >> g >> b; house[i][0] = min(house[i - 1][1], house[i - 1][2]) + r; house[i][1] = min(ho..
[BOJ] 11660번 구간 합 구하기 5 (C++) https://www.acmicpc.net/problem/11660 11660번: 구간 합 구하기 5 첫째 줄에 표의 크기 N과 합을 구해야 하는 횟수 M이 주어진다. (1 ≤ N ≤ 1024, 1 ≤ M ≤ 100,000) 둘째 줄부터 N개의 줄에는 표에 채워져 있는 수가 1행부터 차례대로 주어진다. 다음 M개의 줄에는 네 www.acmicpc.net #include using namespace std; int arr[1025][1025]; int main() { int n, m; scanf("%d %d", &n, &m); int num; for(int i = 1; i
[BOJ] 1918번 후위 표기식 (C++) https://www.acmicpc.net/problem/1918 1918번: 후위 표기식 첫째 줄에 중위 표기식이 주어진다. 단 이 수식의 피연산자는 알파벳 대문자로 이루어지며 수식에서 한 번씩만 등장한다. 그리고 -A+B와 같이 -가 가장 앞에 오거나 AB와 같이 *가 생략되는 등의 www.acmicpc.net #include #include #include using namespace std; int main() { string s; cin >> s; stack st; for(int i = 0; i = 'A' && s[i]
[BOJ] 9251번 LCS (C++) https://www.acmicpc.net/problem/9251 9251번: LCS LCS(Longest Common Subsequence, 최장 공통 부분 수열)문제는 두 수열이 주어졌을 때, 모두의 부분 수열이 되는 수열 중 가장 긴 것을 찾는 문제이다. 예를 들어, ACAYKP와 CAPCAK의 LCS는 ACAK가 된다. www.acmicpc.net #include #include #include using namespace std; int dp[1001][1001]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); string s1, s2; cin >> s1 >> s2; int s1_size = s1.length(); int s2_size = ..
[BOJ] 1916번 최소비용 구하기 (C++) https://www.acmicpc.net/problem/1916 1916번: 최소비용 구하기 첫째 줄에 도시의 개수 N(1 ≤ N ≤ 1,000)이 주어지고 둘째 줄에는 버스의 개수 M(1 ≤ M ≤ 100,000)이 주어진다. 그리고 셋째 줄부터 M+2줄까지 다음과 같은 버스의 정보가 주어진다. 먼저 처음에는 그 www.acmicpc.net #include #include #include #define INF 987654321; using namespace std; int dist[1001]; vector v[100001]; void dijkstra(int start){ dist[start] = 0; priority_queue pq; pq.push({dist[start], start}); while(..