본문 바로가기

Algorithm/BOJ211

[BOJ]14889번: 스타트와 링크 (c++) https://www.acmicpc.net/problem/14889 14889번: 스타트와 링크예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.www.acmicpc.net 방법 1: 백트랙킹#include #include #include using namespace std;const int MAX = 20;int min_dif = 1000;int S[MAX][MAX];int N;// 점수 차이 구하기int get_point_dif(vector& team_s, vector& team_l){ int sum_s = 0; int sum_l = 0; for (int i = 0; i & team_s.. 2020. 5. 21.
[BOJ]14501번: 퇴사 (c++) https://www.acmicpc.net/problem/14501 14501번: 퇴사첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다.www.acmicpc.net 방법 1 : 백트랙킹#include #include using namespace std;int max_sum;void dfs(vector &dates, vector &money, int sum, int index){ // 일의 종료 시점이 주어진 날짜보다 클때 if (index > dates.size()) { return; } // 주어진 날짜에 일을 종료할 수 있을 때 else if (index == dates.size()) { if (max_sum > N; vector dates(N); vector money(N); for (in.. 2020. 5. 20.
[BOJ]1759번: 암호 만들기 (c++) https://www.acmicpc.net/problem/1759 1759번: 암호 만들기첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.www.acmicpc.net #include #include #include #include using namespace std;// 최소 모음 1개, 자음 2개 조건에 만족하는지 검사bool check(string pw){ const string consonant = "aeiou"; int c_cnt = 0; for (char c : pw) { if (consonant.find(c) != string::npos) { ++c_.. 2020. 5. 20.
[BOJ]1260번: DFS와 BFS(c++) https://www.acmicpc.net/problem/1260 1260번: DFS와 BFS첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사이에 여러 개의 간선이 있을 수 있다. 입력으로 주어지는 간선은 양방향이다.www.acmicpc.net  #include #include #include #include using namespace std;// 너비 우선 탐색void bfs(vector>& list, vector& visited, int start){ queue q; q.push(start); visited[start] = .. 2020. 5. 12.