알고리즘 문제해결전략(99)
-
[동적 계획법] DRAGON 드래곤 커브
1. 완전 탐색 이 문제는 다음 과 같은 규칙이 있다 gen 0: gen0 gen 1: gen1 gen 2: gen1 + -gen1 gen 3: gen2 + -gen2 gen 4: gen3 + -gen3 . . . gen n: gen n + -gen n 여기서 -gen1은 gen1의 가운데 부호를 마이너스를 바꾼 것이다. 이를 통해 우리는 완전 탐색 함수를 구현할 수 있다. 1 2 3 4 5 6 7 8 9 10 11 12 std::string minusDragon(int gen) { if(gen == 1) return "FX-YF"; return dragon(gen-1) + "-" + minusDragon(gen-1); } std::string dragon(int gen) { if(gen == 0) re..
2021.01.15 -
[동적 계획법][시간 초과 해결] KLIS: K-th Longest Increasing Sequence
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12..
2021.01.15 -
[동적 계획법][시간 초과] KLIS: K-th Longest Increasing Sequence
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 #include #include #include #include #include #include std::vector cache; int elements[500]; double skip; i..
2021.01.14 -
[동적 계획법] OCR 광학 문자 인식
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 #include #include #include #include #include #include #include using namespace std; st..
2021.01.13 -
[동적 계획법] PACKING 여행짐 싸기
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 #include #include #include #include #include class pac { public: std::string name; int imminence; int w; pac(); pac(std::s..
2021.01.13 -
[동적 계획법] NUMB3RS 두니발 박사의 탈옥
1. 완전 탐색 이 문제는 day만큼 날이 지난다음 q의 마을에 p에서 탈옥한 박사가 있을 확률을 구하는 문제이다. 날마다 박사는 인접한곳으로 이동한다. 그러므로 완전 탐색으로 풀때에는 p에서 시작해서 확률을 곱해가며 모든 경우의 수를 세면서 마지막 날일 때 ret[town] += 해당 경우의 확률 이처럼 더해가면된다 그 후 ret[0] ret[2] 를 호출하게되면 바로 바로 답이 나오게 된다. 2. 점화식 이 문제에서 동적 계획법을 적용하려면 완전 탐색 과는 다르게 뒤에서 부터 생각해야한다. FIND(remainDay, startpoint) = Σ(per(startpoint) * FIND(remainday - 1, next)) remainDay의 날짜가 남았을 떄 startpoint부터 시작하여 교도소..
2021.01.11