목록문제 해결력 훈련 (58)
게임 개발 메모장

▣ 입력예제 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 0 0 ▣ 출력예제 8 #include #include #include using namespace std; int map[10][10], ch[10][10]; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; int cnt = 0; void DFS(int x, int y) { int xx, yy; if (x == 7 && y == 7) { cnt++; } else { for (int i = 0; i < 4; ++i) { xx = x + dx[i]; yy = y + dy[i]; i..

▣ 입력예제 5 8 1 2 12 1 3 6 1 4 10 2 3 2 2 5 2 3 4 3 4 2 2 4 5 5 ▣ 출력예제 13 #include #include #include using namespace std; int map[30][30], ch[30], n, cost = INT_MAX; void DFS(int v, int sum) { if (v == n) { if (sum > n >> m; for (int i = 1; i > ..

▣ 입력예제 5 9 1 2 1 3 1 4 2 1 2 3 2 5 3 4 4 2 4 5 ▣ 출력예제 6 #include #include #include using namespace std; int map[30][30], ch[30], cnt = 0, n; void DFS(int v) { if (v == n) // * 재귀가 종료 지점에 왔느냐? { cnt++; } else { for (int i = 1; i > n >> m; // 정점, 간선 개수 for (int i = 1; i > a >> b; map[a][b] = 1; // 가중치 그래프 ( 인접 행렬 ) } ch[1] = 1; // 방문지점은 다시는 안가기 위해 체크배열을 둔다. DFS(1); cout

▣ 입력예제 6 9 1 2 7 1 3 4 2 1 2 2 3 5 2 5 5 3 4 5 4 2 2 4 5 5 6 4 5 ▣ 출력예제 0 7 4 0 0 0 2 0 5 0 5 0 0 0 0 5 0 0 0 2 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 #include #include #include using namespace std; int map[21][21]; int main() { int n,m,a,b,c; cin >> n >> m; for (int i = 1; i > a >> b >> c; map[a][b] = c; // 가중치 그래프 //map[b][a] = c; // 무방향 그래프일 때는 이것까지 } for (int i = 1; i

▣ 입력예제 4 12 2 4 6 8 ▣ 출력예제 4 #include #include #include using namespace std; int n, m, a[11], cnt = 0; void DFS(int L, int sum) { if (L == n+1) { if (sum == m) { cnt++; } } else { DFS(L+1, sum + a[L]); DFS(L+1, sum); DFS(L+1, sum - a[L]); } } int main() { cin >> n >> m; for (int i = 1; i > a[i]; } DFS(1,0); if (cnt == 0) { cout

#include #include #include using namespace std; int n, ch[11]; void DFS(int L) { if (L == n + 1) { for (int i = 1; i

▣ 입력예제 6 1 3 5 6 7 10 ▣ 출력예제 YES #include #include #include using namespace std; int n, total = 0, a[11], flag = false; void DFS(int L, int sum) { if (sum > (total / 2)) { return; } if (flag == true) { return; } if(L == n+1) { if (sum == (total - sum)) { flag =true; } } else { DFS(L+1, sum +a[L]); DFS(L+1, sum); } } int main() { cin >> n; for (int i = 1; i > a[i]; } DFS(1,0); if (flag == true) {..

▣ 입력예제 10 ▣ 출력예제 12 ▣ 입력예제 1500 ▣ 출력예제 859963392 #include #include #include using namespace std; int a[1501]; int main() { int n,p2,p3,p5, min = INT_MAX; cin >> n; a[1] = 1; p2 = p3 = p5 = 1; for (int i = 2; i

▣ 입력예제 5 5 3 7 2 3 3 7 1 6 1 7 2 5 3 4 4 3 6 4 1 8 7 3 5 2 ▣ 출력예제 10 #include #include #include using namespace std; int map[51][51]; int main() { int dx[4] = {-1,0,1,0}; int dy[4] = {0,1,0,-1}; int n,k,flag,cnt = 0; cin >> n; for (int i = 1; i map[i][j]; } } for (int i = 1; i