diff --git a/week08/wimmings/.gitkeep b/week08/wimmings/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week08/wimmings/10844.cpp b/week08/wimmings/10844.cpp new file mode 100644 index 0000000..c2cab3f --- /dev/null +++ b/week08/wimmings/10844.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +int n; +int ans; +/* + dp[i][j] : 숫자 길이가 i, 일의 자리 숫자가 j일 때 계단수의 개수 + 길이가 i-1인 숫자 중 일의 자리가 j+1 인 경우 + + + 길이가 i-1인 숫자 중 일의 자리가 j-1 인 경우 + */ +int dp[102][10]; +int mod = 1000000000; + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> n; + + for (int i = 1; i <= 9; ++i) { + dp[1][i] = 1; + } + + for (int i = 2; i <= n; ++i) { + for (int j = 0; j <= 9; ++j) { + if (j+1 <= 9) { + dp[i][j] = (dp[i][j]%mod + dp[i-1][j+1]%mod)%mod; + } + if (j-1 >= 0) { + dp[i][j] = (dp[i][j]%mod + dp[i-1][j-1]%mod)%mod; + } + } + } + for (int i = 0; i <= 9; ++i) { + ans = (ans%mod + dp[n][i]%mod)%mod; + } + cout << ans << '\n'; + + return 0; +} \ No newline at end of file diff --git a/week08/wimmings/15684.cpp b/week08/wimmings/15684.cpp new file mode 100644 index 0000000..7819ba7 --- /dev/null +++ b/week08/wimmings/15684.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; +int n, m, h; + +bool ladder[32][12]; +int ans = 5; + +bool isSuccess() { + for (int j = 1; j <= n; ++j) { + int original_j = j; + + for (int i = 1; i <= h; ++i) { + if (ladder[i][j]) { + j++; + } + else if (ladder[i][j-1]) { + j--; + } + } + if (j != original_j) return false; + } + return true; +} + +void dfs(int cnt, int H) { + if (cnt > 3) return; + // 만약 조작 성공 -> cnt 최솟값 갱신 + if (isSuccess()) { + ans = min(ans, cnt); + return; + } + + for (int i = H; i <= h; ++i) { + for (int j = 1; j < n; ++j) { + if (ladder[i][j] || ladder[i][j-1] || ladder[i][j+1]) continue; // 자기 자신과 양 옆을 봤을 때 사다리가 하나라도 있으면 패스 + ladder[i][j] = 1; + dfs(cnt+1, i); + ladder[i][j] = 0; + } + } +} + + +int main() { + ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); + cin >> n >> m >> h; + for (int i = 0; i < m; ++i) { + int a, b; cin >> a >> b; // b, b+1 세로선, a위치에서 연결 + ladder[a][b] = 1; + } + dfs(0, 1); + + if (ans == 5) ans = -1; + cout << ans << '\n'; + + return 0; +} \ No newline at end of file