목록ALGORITHM/BAEKJOON (76)
MY MEMO
#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..
일단 이 문제를 보고 처음 든 생각은 바로 한칸을 뛰거나 아니면 두칸을 뛰고 대신 3개를 연속으로 뛰지 않는 문제를 생각했다.그래서 첫번째 코드를 짰다. 첫번째 실패#include #include #include #include using namespace std; int cup_count, drinking_amount; vectoralchol; void drinking_wine(int index, int before_flag, int result) { if (index >= cup_count) { drinking_amount = max(result, drinking_amount); return; } if (before_flag < 2) //만약 이전에 한칸 뛰었으면 { drinking_wine(inde..
이게 원래 짰던 코드이다만약 3자리 수라면 100이고 111까지만 확인하면 된다 왜냐하면000부터 011까지는 0이 맨 앞에 있기 때문에 어짜피 되지 않는다. 따라서 cache를 두고 x는 자릿 수 y는 decimal숫자로 해서만약 2자리수의 decimal 3을 미리 구해놓았다면되는지 되지 않는지를 판단하는 것이다. 하지만 문제가 있었다이것이 범위는 90자리 즉 pow(2,90)인 것이다.vector로 저 범위의 공간을 만들 수가 없다. #include #include #include #include #include using namespace std; vector cache = vector(91, vector(pow(2, 20), -1)); string dec_to_bin(unsigned long lo..
오류 코드#include #include #include #include using namespace std; vector cache; #define INT_MAX 2147483647 int cal(int remain, int result) { if (remain == 1) return result-1; int &ret = cache[remain]; if (ret != INT_MAX) return ret; if (remain % 3 == 0) ret = min(ret, cal(remain / 3, result + 1)); if (remain % 2 == 0) ret = min(ret, cal(remain / 2, result + 1)); ret = min(ret, cal(remain - 1, result..