목록ALGORITHM (123)
MY MEMO
#include #include #include using namespace std; vector map = vector(12,0); int fibo(int n) { if (n == 1) return 1; if (n == 2) return 2; if (n == 3) return 4; return fibo(n - 1) + fibo(n - 2) + fibo(n - 3); } int main() { cout
자리수 0으로시작 1로시작 2로시작 3으로시작 4로시작 5로시작 6으로시작 7로시작 8로시작 9로시작 합 출력 1 1 1 1 1 1 1 1 1 1 1 10 10 2 10 9 8 7 6 5 4 3 2 1 55 55 3 55 45 36 28 21 15 10 6 3 1 220 220 4 220 165 120 84 56 35 20 10 4 1 715 715 5 715 495 330 210 126 70 35 15 5 1 2002 2002 6 2002 1287 792 462 252 126 56 21 6 1 5005 5005 7 5005 3003 1716 924 462 210 84 28 7 1 11440 1433 8 11440 6435 3432 1716 792 330 120 36 8 1 24310 4296 9 243..
#include #include #include #include #include #include #include using namespace std; #define PAIR pair #define MAXNUM 123456789 int main() { int row_size, col_size; cin >> row_size >> col_size; vectormovement; vector dist = vector(col_size, vector(row_size, MAXNUM)); vectormap = vector(col_size); priority_queue cache; movement.push_back(make_pair(1, 0)); movement.push_back(make_pair(0, 1)); movem..
이문제는 혼자 못풀었다...정말 어려웠다..DFS로 풀면 되겠지 했는데..대체 어디서 visit를 풀어줘야되고 어디서 안풀어줘야되고를 몰랐다 근데 이게 웬걸.. http://blog.eairship.kr/268 깔끔하게 정리해놓은 DFS의 이론 아래에 이것과 비슷한 문제가 있었다단지 이 사이트의 문제는 시작과 끝점이 정해져있고 minimum을 찾는것이고 그리고 문제해결기법의 문제는 시작점만 있고 maximum을 찾는 것이다. 그렇다면!!! 그 두개의 조건만을 변경해주면 되는 것이다. 아 잡힐듯 말듯해서 풀지 못했는데 이렇게 쉽게 풀리다니이제 정신 똑디 잡고 문제 풀어야겠다 이 문제의 내가 헷갈린 가장 큰 visit라는 부분은map을 변경하여 간단하게 해결되었다 어짜피 1인 부분은 visited로 설정해줬..
#include #include #include #include #include #include using namespace std; int number_count; string number; vector big; int DP(int rest, int index) { if (number_count > for_count; while (for_count--) { fcin >> number_count >> number >> difference; DP(difference, 0); for (int j = 0; j < number_count; j++) fcout
0을 처리하는 것을 몰랐다..0이 예외라니! 그 이후에 수정을 했는데아 이게 왜 안도는지 모르겠다내가 생각한 모든 예외사항을 처리했는데 왜 안돌지..심지어 코드도 똑같은 것같은데 틀렸다고 뜬다..흠.. 오답#include #include #include #include #include using namespace std; string code; int code_count, flag; vector cache; int code_breaking(int index) { if (index == code_count) return 1; int & ret = cache[index]; if (ret != 0) return ret; if (code[index] - '0' == 0) { flag = 0; return 0; ..
이문제는 못풀었다..어려웠다..정답을 보고 사람들은 천재라고 생각했다.. 신박한 방법.. 일단 처음에는 DP의 완전 기본적인 구조를 이용했다.그 합을 만드는 데 얼마나 작은 수가 필요한지 minimum을 저장했다. 그리고 이후 그 minimum을 구한 적이 있으면 return하면서 풀었다. 아 그리고 1부터 0개씩 써가면서 모든 수를 다 돌아보는 형식이다.시간이 오래 걸릴 만 했다..ㅎㅎ 충분히 시간을 줄일 수 을 꺼라 생각했는데 코드로 어떻게 짜야하는지 몰랐다. 첫번째(오답)#include #include #include #include using namespace std; #define MAX 1e6 int sum_coin_count, sum_coin; vector coin; vector cache;..
#include #include #include #include using namespace std; int bamboo_count; vectorbamboo; vectorcache; int eating_bamboo(int x, int y, int before_bamboo) { if (bamboo[x][y] = 0) ret = max(ret, eating_bamboo(x - 1, y, bamboo[x][y]) + 1); if (y - 1 >= 0) ret = max(ret, eating_bamboo(x, y - 1, bamboo[x][y]) + 1); if (x + 1 < bamboo_count) ret = max(ret, eating_bamboo(x + 1, y, bamboo[x][y]) + 1); if..
첫번 째 코드#include #include #include #include using namespace std; vector number; vector cache; int main() { ifstream fcin; fcin.open("1912_input.txt"); int number_count; fcin >> number_count; number = vector(number_count); cache = vector(number_count, -1); for (int j = 0; j > number[j]; int max_sum = -1; cache[0] = number[0]; for (int j = 0; j < number_count - 1; j++) { ..
#include #include #include using namespace std; #define MOD 1000000000 int input; vectorcache; //첫번째 : 자리수 & 두번째 : 숫자 long long check_stair(int index, int num, int before_num) { if (index 9) return 0; if (index >= input) return 1; long long & ret = cache[index][num]; if (ret != 0) return ret; return ret += (check_stair(index + 1, num - 1, num) + check_stair(index + 1, num..