목록ALGORITHM (123)
MY MEMO
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { int n; scanf("%d", &n); vector map(n, vector(n)); for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) scanf("%d", &map[x][y]); vectorDP(n); for (int x = 0; x < n; x++) DP[x] = x; int answer = 2e9; do { bool ok = true; int sum = 0; for (int x = 0; x < n - 1; x++) { if (map[DP[x]][DP[x + 1]]) sum += ma..
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { int n, vip_count, vip_seat; scanf("%d %d", &n, &vip_count); int start = 1,Max = 0; vectorCal, DP(41); for (int j = 0; j
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { vectormap(201), DP(201, 0); int n; scanf("%d", &n); for (int j = 0; j map[k]) Max = max(DP[k], Max); } DP[j] = Max + 1; } int answer = 0; for (int j = 0; j < n; j++) answer = max(ans..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; int row, col; vectorDP(16, vector(16, -1)); int find_way(int x, int y, int end_x, int end_y) { int&ret = DP[x][y]; if (ret != -1) return ret; if (x == end_x && y == end_y) return 1; int num1 = 0, num2 = 0; if (x + 1
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vectormap(2001); vectorDP(2001, vector(2001, -1)); int is_palindrom(int start, int end) { int &ret = DP[start][end]; if (ret != -1) return ret; if (start > end) return 1; if (is_palindrom(start + 1, end - 1)==1) { if (map[start] == map[end]) return ret = 1; else return ret = 0; } else return ret = 0; } int main() { int n, q_c..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vector DP(68, -1); long long koong(int n) { long long&ret = DP[n]; if (ret != -1) return ret; return ret = koong(n - 1) + koong(n - 2) + koong(n - 3) + koong(n - 4); } int main() { int for_count,n; scanf("%d", &for_count); DP[0] = 1; DP[1] = 1; DP[2] = 2; DP[3] = 4; for (int j = 0; j < for_count; j++) { scanf("%d", &n); print..
#define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; vectorDP(1000001,-1); long long fibo(int n) { long long &ret = DP[n]; if (ret != -1) return ret; return ret = (fibo(n - 1) + fibo(n - 2))%15746; } int main() { int n; scanf("%d", &n); DP[1] = 1; DP[2] = 2; printf("%lld", fibo(n)% 15746); return 0; } 문제를 제대로 읽자!
가장 긴 증가하는 부분수열을 1. 아래에서 부터 위로 2. 위에서 부터 아래로 3. 두개를 더한 것의 최대 4. 자신의 값이 더해졌으니까 -1 을 해주면 된다고 한다.. 이러면서 배우는 거지.. #define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { int n; scanf("%d", &n); vector Up(1001,0), Down(1001,0), input(1001); for (int j = 0; j < n; j++) scanf("%d", &input[j]); int Max; for (int x = 0; x < n; x++) { Max = 0; for (int y = 0; y < x;y++)..
#define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; int main() { int n; vector map(501, vector(501)); scanf("%d", &n); for (int y = 0; y < n; y++) for (int x = 0; x 0; y--) for (int x = 0; x < y; x++) map[x][y - 1] += max(map[x][y], map[x + 1][y]); printf("%d", map[0][0]); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include #include #include #include using namespace std; int row, col; vectormap(1001, vector(1001)); vectorDP(1001, vector(1001, -1)); int square(int x,int y) { if (x == row - 1 || y == col - 1) return map[x][y]; if (map[x][y] == 0) return 0; int &ret = DP[x][y]; if (ret != -1) return ret; int num1 = 0, num2 = 0,num3 = 0; if (x + 1 < row) num1 = square(x + 1, y);..