본문 바로가기

백준 알고리즘/다이나믹 프로그래밍75

백준 1328번 C++ #include #include #include using namespace std; const int MAX = 101; const int MOD = 1000000007; int n, l, r, answer = 0; long long building[MAX][MAX][MAX]; long long calway(int num, int left, int right) { if (num == n && left == l && right == r) return 1; if (num > n) return 0; if (left > l || right > r) return 0; long long &answer = building[num][left][right]; if (answer != -1) return answer; .. 2019. 8. 25.
백준 1958번 C++ #include #include #include #include using namespace std; const int MAX = 101; string s1, s2, s3; int maxlong[MAX][MAX][MAX]; struct Move { int x, y, z; }; Move mv[7] = { {1,0,0}, {1,0,1}, {1,1,0}, {0,1,1}, {0,1,0}, {0,0,0}, {0,0,1} }; int maxstr(int i, int j, int k) { if (i >= s1.size() || j >= s2.size() || k >= s3.size()) return 0; int &answer = maxlong[i][j][k]; if (answer != -1) return answer.. 2019. 8. 25.
백준 10835번 C++ #include #include #include using namespace std; const int MAX = 2001; int n; int leftnum[MAX], rightnum[MAX]; int cache[MAX][MAX]; int maxscore(int lindex, int rindex) { if (lindex >= n || rindex >= n) return 0; int &answer = cache[lindex][rindex]; if (answer != -1) return answer; answer = 0; if (leftnum[lindex] > rightnum[rindex]) answer = maxscore(lindex, rindex + 1) + rightnum[rindex]; answer.. 2019. 8. 24.
백준 2225번 C++ #include #include #include using namespace std; const int MAX = 201; const int MOD = 1000000000; int n, k; int num[MAX][MAX]; int calway(int sum, int counts) { if (counts == 1) return 1; int &answer = num[sum][counts]; if (answer != -1) return answer; answer = 0; for (int i = 0; i > n >> k; memset(num, -1, sizeof(num)); cout 2019. 8. 24.