Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[week-08] 10844, 15684 #49

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed week08/wimmings/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions week08/wimmings/10844.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <algorithm>

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;
}
63 changes: 63 additions & 0 deletions week08/wimmings/15684.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <algorithm>

using namespace std;
int n, m, h;

bool ladder[32][12];
int ans = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어차피 cnt > 3 이면 return 시키는 거라서 굳이 INT_MAX 일 필요가 없군요 ..!


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;
}