PS 12

백준 DP모음

1947번 [선물 전달]완전 순열: 일렬로 배열한 대상들의 위치를 재조정했을 때, 모든 대상이 자기 위치에 있지 않도록 하는 배열 방법 점화식: D[n] = (n-1)(D[n-1] + D[n-2])ll dp[1000001];int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; dp[1] = 0; dp[2] = 1; for (ll i = 3; i  13398번 [연속합 2]수가 하나 제거되면 2부분으로 나뉜다. ㅡ> 2개의 dp배열 사용int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector v; int ..

PS 2025.02.20

백준 2343번 [기타 레슨]

이진 탐색, 매개 변수 탐색이진 탐색의 start, end, mid을 배열의 값에만 국한시키지 말고 문제와 관련된 매개 변수로 해본다.ㅡ> 정렬된 배열이 아니더라도 이진 탐색 사용 가능N, M int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector v; int end = 0; int start = 0; for (int i = 0; i > x; v.push_back(x); end += x; start = max(start, x); } while (start mid) { count++; sum = 0; } sum += v[i]; } if (count > m)..

PS 2025.02.19

백준 1253번 [좋다]

투 포인터, 이분탐색 시간복잡도 n ㅡ> logn 만들 때 고려시작 포인트 잡기포인터 이동규칙 세우기종료 조건 만들기포인터가 경계값에 있을 때 따지기#include #define ll long long#define pii pair#define pll pair#define tpi tuple#define tpl tuple#define all(x) x.begin(), x.end()#define INF 0x3f3f3f3f#define MOD 100000007using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector v; ll n; cin >> n; ll start = 0; ll end = n-1; ll..

PS 2025.02.11