분류 전체보기
[백준 9084번][C++] 동전
### 분류 다이나믹 프로그래밍(dp), 배낭 문제(knapsack) #include #include using namespace std; int main() { int test; cin >> test; //indexdml 금액을 달성하는 방법의 개수 vector total_cnt(10000, 0); while(test--){ //코인 종류 개수 입력 int coin_cnt; cin >> coin_cnt; //코인 종류 입력 vector coin_list; for (int i = 0; i > input; coin_list.push_back(input); } //방법을 찾아야하는 목표 금액 int target_money; cin >> target..
[백준 1715번][C++] 카드 정렬하기
#include #include using namespace std; int main() { //테스트 케이스 입력받기 int n; cin >> n; //총 계산횟수 구하는 변수 int total_cnt = 0; //우선순위 큐를 오름차순으로 저장 priority_queue pq; //카드 더미수 입력받고 우선순위 큐에 저장 while (n--) { int input; cin >> input; pq.push(input); } //큐 안에 저장된 원소가 1개가 될 때까지 //가장 적은 수를 가진 더미 2개를 뽑아 더해서 다시 더미에 넣고 //합 한 수는 총 계산 횟수에 업데이트 해줌 while (pq.size() != 1) { int input1, input2; input1 = pq.top(); pq.po..
![[백준 11053번][C++] 가장 긴 증가하는 부분 수열](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FHXMpt%2FbtrLj94Yhjb%2FAAAAAAAAAAAAAAAAAAAAAGqJPZtmPg4z1SGMT-QVr2UE7Xd9DDTFAcV1At4V-_wi%2Fimg.jpg%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1759244399%26allow_ip%3D%26allow_referer%3D%26signature%3DgnKxswNd%252FOrBKJsp4Yc3WtO6trE%253D)
[백준 11053번][C++] 가장 긴 증가하는 부분 수열
#include #include using namespace std; int main() { int n; cin >> n; //수열 저장할 벡터 vector list(n); //수열의 최대길이 저장할 벡터 //초기 길이는 1 vector max(n,1); //수열 입력받기 int input; for (int i = 0; i > input; list[i] = input; } int max_length = 1; //index 1부터 최대길이 저장 for (int i = 1; i = 0; j--) { //자신의 값보다 작고 최대길이가 자신보다 클 때 그 수의 +1을 저장 if (list[..
[백준 23972번][C++] 악마의 제안
#include #include using namespace std; int main() { long long K, N; cin >> K >> N; //N이 1일때만 항상 손해 if (N == 1) { cout (N * K) % (N - 1) //소수점이 나올때 그보다 크고 가까운 정수로 출력 if ((N * K) % (N - 1)) { cout
[백준 3003번][C++] 킹, 퀸, 룩, 비숍, 나이트, 폰
#include using namespace std; int main() { //각 말의 원래 있어야 할 개수 int chess[6]{1,1,2,2,2,8}; //현개 가지고 있는 말의 수 빼고 출력 int input; for (int i = 0;i > input; chess[i] -= input; cout
[백준 10807번][C++] 개수 세기
#include using namespace std; int main() { //-100 ~ 100 의 수의 개수를 담기위한 201이상 크기의 배열 int list[204]{ 0, }; int test; cin >> test; int input; //수 입력받고 그에맞는 INDEX의 수 증가 for (int i = 0;i > input; //음수일 때는 201을 더해주어 INDEX 100이상으로 취급 if (input > input; if (input < 0) { input += 201; } cout
[백준 1181번][C++] 단어 정렬
#include #include #include #include using namespace std; int main() { int test; cin >> test; vector v; //단어 리스트 저장할 벡터 vector size; //단어들의 길이 저장할 벡터 for (int i = 0;i > str; //문자 입력받음 v.push_back(str); //단어 저장 size.push_back(str.size()); //단어의 길이 저장 } sort(size.begin(), size.end()); //단어의 길이 오름차순 정렬 size.erase(unique(size.begin(), size.end()), size.end()..
[백준 2178번][C++] 미로 탐색
#include #include #include #include using namespace std; //미로 표 vector miro(102, vector(102, -1)); //방문 확인용 vector isVisited(102, vector(102, 0)); //축 이동 int MovePointx[4] = { -1,1,0,0 }; int MovePointy[4] = { 0,0,-1,1 }; //행,렬 int height, width; void FindMin(int x, int y) { //bfs를 위한 좌표저장 큐 queue Point_List; Point_List.push(make_pair(x, y)); while (!Point_List.empty()) { int x = Point_List.fron..
[백준 7662번][C++] 이중 우선순위 큐
#include #include #include using namespace std; int main() { int test; cin >> test; while (test--) { //각각 최대힙과 최소힙 priority_queue min_heap; priority_queue max_heap; //삭제된 인덱스 저장 map del_idx; // 입력 데이터의 수 int input; cin >> input; for (int i = 0; i > c >> check_num; //삽입연산일 때 if (c == 'I') { //최대힙 최소힙 둘다 값저장 max_heap.push(check_num); min_h..
[백준 9095번][C++] 1, 2, 3 더하기
#include using namespace std; //각 인덱스에 맞는 횟수 저장할 배열 선언 int num[12]; int main() { int test; cin >> test; //계산을 위한 0과 1 초기화 num[0] = 1; num[1] = 1; num[2] = 2; //점화식에 맞게 횟수 채워주기 for (int i = 3;i > input; cout