본문 바로가기

알고리즘268

7562 나이트의 이동 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include #include #include using namespace std; int dx[8] = { 1,2,2,1,-1,-2,-2,-1 };int dy[8] = {-2,-1,1,2,2,1,-1,-2};int bfs(int stX, int stY, int endX, int endY, int width) { queue q; q.push(make_pair(0, make_pair(stY, stX))); int chk[305][305] = { 0 }; chk[stY][stX] = 1; while (!q.empty()) { int.. 2020. 1. 14.
7576 토마토 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061#include #include #include using namespace std; queue q;int arr[1005][1005] = { 0 };int chk[1005][1005] = { 0 };int dx[4] = { 1,-1, 0,0 };int dy[4] = { 0,0,1,-1 }; int bfs(int sum, int endY, int endX) { int rst = 0, len; while (!q.empty()) { len = q.front().first; int y = q.front().se.. 2020. 1. 14.
2178 미로 탐색 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include #include #include using namespace std; char arr[101][101] = { 0 };int chk[101][101] = { 0 };int minDist = 1000000000; void bfs(int endY, int endX) { queue q; q.push(make_pair(1, make_pair(0, 0))); chk[0][0] = 1; while (!q.empty()) { int len = q.front().first; int y .. 2020. 1. 13.
1182 부분수열의 합 1234567891011121314151617181920212223242526#include int arr[50] = { 0 };int rst = 0, n, s; void sum(int idx, long long curSum) { if (idx > n) return; if (curSum + arr[idx] == s) rst++; sum(idx + 1, curSum); sum(idx + 1, curSum + arr[idx]);} int main() { scanf("%d %d", &n, &s); for (int i = 1; i 2020. 1. 13.
1748 수 이어쓰기1 1234567891011121314151617181920212223242526#include #include int main() { long long n; scanf("%lld", &n); long long tenN = 1; while (tenN 2020. 1. 13.
2231 분해합 1234567891011121314151617181920212223242526#include #include int main() { int n; scanf("%d", &n); int sum = 0, i; for (i = 1; i 0) { sum += (mok % 10) / one; mok /= 10; } if (sum == n) { printf("%d", i); break; } } if (i == n) printf("0");}Colored by Color Scriptercs 각 자릿수 합 문제가 자주 출제된다.정형화 된 풀이를 기억하자 2020. 1. 13.
7568 덩치 12345678910111213141516171819202122232425262728293031#include int arr[60][3] = { 0 };int rank_arr[60] = { 0 }; int main() { int n; scanf("%d", &n); for (int i = 1; i 2020. 1. 13.
2309 일곱 난장이 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#include int arr[10] = { 0 };int rst[10] = { 0 }; void sorting() { for (int i = 1; i 2020. 1. 12.
1065 한수 12345678910111213141516171819202122232425#include int main() { int n; scanf("%d", &n); int rst = 0; for (int i = 1; i 2020. 1. 12.
문자열 정리> 기본 기법들 모음 2020. 1. 12.
DP정리> 동전 문제 2020. 1. 12.
DP 정리> 타일 채우기 # 문제 모음 11726번 - 2*n 타일링 11727번 - 2*n 타일링 21793번 - 타일링 (2*n 타일링. 큰 숫자 다루기)2133번 - 타일 채우기 (3*n 타일) 2718번 - 타일 채우기 (4*n 타일)-----------------------------------------1720번 - 타일 코드 (타일 뒤집기) : 기본 2*n 타일 문제에서, 중복되는 경우를 제거하기 위해 교집합을 더한 다음 /2 연산을 해준다-----------------------------------------1904번 - 01타일 (숫자 다루기) : 그냥 나열하다 보면 알아서 규칙이 나온다 # 기본적인 접근 방식 - Top Down 접근 : 전체 완성본에서, width-1, width-2... 등등을 고려해서 식.. 2020. 1. 12.