목록ALGORITHM/BAEKJOON (76)
MY MEMO
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vectorDP(1001, vector(1001, -1)); int binomial_coefficient(int n, int k) { if (n == k) return 1; if (k == 1) return n; int&ret = DP[n][k]; if (ret != -1) return ret; return ret = (binomial_coefficient(n - 1, k - 1) + binomial_coefficient(n - 1, k)) % 10007; } int main() { int n, k; scanf("%d %d", &n, &k); printf("%d", binomia..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vectorDP(201, vector(201, -1)); int Decom(int N, int k) { int&ret = DP[N][k]; if (ret != -1) return ret; int result = 0; for (int j = N; j >= 0; j--) result = (result + Decom(j, k - 1)) % 1000000000; return ret = result % 1000000000; } int main() { int N, k; scanf("%d %d", &N, &k); for (int j = 0; j
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vectormap(101, vector(101)); vectorDP(101, vector(101, -1)); int max_line; long long jump(int x, int y) { if (x == max_line - 1 && y == max_line - 1) return 1; long long &ret = DP[x][y]; if (ret != -1) return ret; long long num1 = 0, num2 = 0; if (x + map[x][y] < max_line && map[x][y] != 0) num1 = jump(x + map[x][y], y); if (..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; //시간초과 int row, col; vectormap, DP; int stair(int x, int y) { int&ret = DP[x][y]; if (x == row - 1 && y == col - 1) return ret = 1; if (ret != -1) return ret; ret = 0; int num1=0, num2=0, num3=0, num4=0; if (x + 1 < row && map[x + 1][y] < map[x][y]) num1 = stair(x + 1, y); if (y + 1 < col && map[x][y + 1] < map[x][y]) num2 = ..
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int n; vectormap(501, vector(501)), DP(501, vector(501, -1)); int eating(int x, int y) { int&ret = DP[x][y]; if (ret != -1) return ret; int num1 = 0, num2 = 0, num3 = 0, num4 = 0; if (x + 1 map[x][y]) num1 = eating(x + 1, y); if (y + 1 map[x][y]) num2 = eating(x, y + 1); ..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; int main() { int n; scanf("%d", &n); vectorDP(2, vector(3, 0)); for (int j = 0; j < 3; j++) DP[0][j] = 1; int k = 0; long long answer = 0; for (int j = 0; j < n - 1; j++) { DP[!k][0] = (DP[k][0] + DP[k][1] + DP[k][2]) % 9901; DP[!k][1] = (DP[k][0] + DP[k][2]) % 9901; DP[!k][2] = (DP[k][0] + DP[k][1]) % 9901; k = !k; } k % 2 =..
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { int n; vectormap(1001, 0), DP(1001, 0); scanf("%d", &n); for (int j = 0; j map[k]) Max = max(Max, DP[k]); } DP[j] = Max + 1; } Max = 0; for (int j = 0; j < n; j++) Max = max(Max,..
#include #include #include using namespace std; int dp[1001][1001]; int main() { string a, b; cin >> a >> b; int al_en = a.length(); int b_len = b.length(); for (int i = 0; i < al_en ; ++i) { for (int j = 0; j < b_len ; ++j) { if (a[i] == b[j]) dp[i + 1][j + 1] = dp[i][j] + 1; else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); } } cout
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int cookies_count; //가장 긴 증가하는 부분 수열 int eatCookie(vector cookies) { int answer = 0; vector DP(cookies_count + 1, 0); for (int j = 0; j cookies[k]) if (Min < DP[k]) Min = DP[k]; } DP[j] = Min + 1; answer = max(DP[j], answer); } return..
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int row, colum; vectormap(1001, vector(1001, 0)); vectorcache(1001, vector(1001, -1)); int DP(int x, int y) { if (x == row - 1 && y == colum - 1) return map[x][y]; int &ret = cache[x][y]; if (ret != -1) return ret; int num1 = 0, num2 = 0, num3 = 0; if (x + 1 < row) num1 = DP(x + 1, y); if (y + 1 < colum) num2 = DP(x,..