> >
본문 바로가기

Algorithm

(31)
[BOJ] 30445번 행복 점수 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int main(){ FASTIO; string s; int ph = 0, pg = 0; getline(cin, s); for (int i = 0; i  - 부동 소수점 오차!
[BOJ] 14503번 로봇 청소기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 55;int n, m, r, c, d, res;int arr[MAXN][MAXN];int dx[] = {-1, 0, 1, 0};int dy[] = {0, 1, 0, -1};bool boundary(int x, int y){ return x >= 0 && x = 0 && y > n >> m >> r >> c >> d; for (int i = 0; i > arr[i][j]; } } while(true){ if(!arr[r][c]){ arr[r]..
[BOJ] 2296번 건물짓기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 1005;int DP[2][MAXN];int n;vector, int>> v;void solved(int flag = false){ int k = 0; if (flag) { reverse(v.begin(), v.end()); k = 1; } for (int i = 0; i = 0; j--){ if (y1 > v[j].first.second){ DP[k][i] = max(DP[k][i], DP[k][j] + c); } ..
[BOJ] 4136번 Pousse #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int n;bool flag;const int MAXN = 105;char arr[MAXN][MAXN];bool check() { int X = 0, O = 0; for (int i = 0; i O) { cout X) { cout 0; j--) arr[idx][j] = arr[idx][j - 1]; arr[idx][0] = c; } else if (dir == 'R'){ for (int i = n - 1; i >= 0; i--) ..
[BOJ] 15683번 감시 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 10;int n, m, sz, res = 1e6;int arr[MAXN][MAXN];bool visited[MAXN][MAXN];vector> cctv;int dx[] = {-1, 0, 1, 0}; // int dy[] = {0, 1, 0, -1};void solved(int x, int y, int i){ i %= 4; while(true){ x += dx[i]; y += dy[i]; if (!(x >= 0 && x = 0 && y > n >> m; for (int i = 0..
[BOJ] 19321번 Longest Increasing Subsequence #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 100005;int arr[MAXN];bool cmp(pair p1, pair p2){ if (p1.first == p2.first){ return p1.second > p2.second; } return p1.first > n; vector> v; for (int i = 1; i > num; v.push_back({num, i}); } sort(v.begin(), v.end(), cmp); for (int i = 0; i  문제가 정말 짧은데 뭐라고 하는지 잘 모르겠었다. ..
[BOJ] 25759번 들판 건너가기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 100005;int arr[MAXN];int DP[MAXN][105];int main(){ FASTIO; int n; cin >> n; for (int i = 1; i > arr[i]; memset(DP, -1, sizeof(DP)); DP[1][arr[1]] = 0; for (int i = 2; i  가장 먼저 떠오르는 생각은 DP[i] = DP[j] + (arr[i] - arr[j])^2 ( 1당연히 O(N^2)으로 시간초과를 받는 해결법이다. 조건을 보다가 Ai가 이렇게 수치가 작아야할 이유가 없다..
[BOJ] 1062번 가르침 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 55;int n, k, res;string s[MAXN];bool visited[26];void Backtracking(int cnt, int idx){ if (cnt == k){ int tmp = 0; for (int i = 0; i > n >> k; for (int i = 0; i > s[i]; visited['a' - 'a'] = true; visited['n' - 'a'] = true; visited['t' - 'a'] = true; visited['i' - 'a'] = tr..