본문 바로가기
백준 12865 C++ dp를 어떤 값으로 측정할지가 관건이었다.dp의 index를 남은 무게로 설정하고 푼 코드이다.#include using namespace std;int n, k;int dp[100010]; //해당 무게가 남았을 때 최대 Valuevector> stufs; //무게, 가치int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; int w, v; for (int i = 0; i > w >> v; stufs.push_back({ w, v }); } int result = 0; for (int i = 0; i 2025. 5. 8.
백준 11054 C++ #include using namespace std;typedef long long ll;int n;int arr[1010];int dp[1010][2]; //first = index, second [0] = 현재 위치가 가장 낮은 지점일 때의 수, [1] = 현재가 가장 높은 지점일 떄의 수.int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fill(&dp[0][0], &dp[0][0] + 1010 * 2, 1); cin >> n; for (int i = 1; i > arr[i]; } //cout 0; j--) { //자신보다 이전에.. 2025. 4. 1.
백준 10844 C++ #include using namespace std;typedef long long ll;//길이가 n인 계단수 -> n=2인 경우 10,12,21,23,32,34,43,45,54,56 // 65,67,78,76,87,89,98 // 1의 경우 1,2,3,4,5,6,7,8,9 이런 느낌 ㅇㅇint n;int divNum = 1e9;int dp[110][10];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; dp[1][0] = 0; for (int i = 1; i = 0) dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % divNum; if (j + 1 기본 아이디어는 0.. 2025. 3. 30.
백준 1932 C++ #include using namespace std;int n;//현재 층에서 선택된 수의 대각선 왼쪽 또는 대각선 오른쪽에 있는 것 중에서만 선택할 수 있다.// = arr로 봤을 땐 i or i+1 이다.int arr[510][510];int dp[510][510];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i > arr[i][j]; } } dp[1][1] = arr[1][1]; for (int i = 1; i 다음 층에 있는건 현재 index와 index + 1이기에 다음과 같이 해서 성공했다. 2025. 3. 27.
백준 1149 C++ #include using namespace std;struct HomeStruct{ int r=0; int g=0; int b=0;};//주변 집(-1, + 1)의 색과 같지 않아야한다.int n;HomeStruct arr[1010];int dp[1010][3];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int r, g, b; for (int i = 1; i > r >> g >> b; arr[i].r = r; arr[i].g = g; arr[i].b = b; //첫 색깔을 칠했을 때의 최소값. dp[i][0] = min(dp[i - 1][1] + r, dp[i - 1][2] + r); dp[i][1.. 2025. 3. 27.
백준 1940 C++ #include using namespace std;int n; //> n; cout 간단하게 생각할 수 있는 문제였다. 2025. 3. 27.
백준 11066 C++ #include using namespace std;int testCase;int n;int arr[510];int sum[510];int dp[510][510];int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> testCase; while (testCase--) { cin >> n; for (int i = 1; i > arr[i]; //dp[i][i] = arr[i]; sum[i] = sum[i - 1] + arr[i]; //누적합 } for (int len = 1; len 처음엔 (dp[start][mid] + dp[mid+1][end] ) * 2라고 생각했는데이건 전체의 합을 나타내야하는데 dp는 최.. 2025. 3. 26.
백준 11049 C++ 와.. 어려웠다 이 문제#include using namespace std;int n;pair arr[510];int dp[510][510];int main() { cin >> n; for (int i = 1; i > arr[i].first >> arr[i].second; } for (int len = 1; len len으로 총 구할 범위를 정해주고start로 구할 범위의 시작점을 정해준다.그리고 end = len + start이니까 start 부터 len까지의 연산 횟수 최소값을 저장하는 dp가dp[start][end]이다.mid는 어느 값이 최소인지 모르기에 start부터 end는 포함하지 않고 (mid+1을 하기에 end는 포함 X)모든 구역을 돌면서 최소값을 구한다. 2025. 3. 26.
Delegate를 인자로 사용하기 위한 방법 - 구조체 왜 Delegate를 인자로 사용하지 못할까?간단한 내부 구조DECLARE_DELEGATE_OneParam과 같이 선언한 Delegate 타입은 함수 포인터 + 캡처 객체주소를 포함하는 구조이다.MyDelegate.AddUObject(this, &AClassName::FunctionName);다음과 같이 사용한다면 AClassName이 함수 포인터(힙에 할당)이며 this가 캡처 객체 인스턴스 주소이다.즉, 내부적으론 어떤 함수를 가리키는 포인터, 그 함수가 멤버 함수라면 해당 객체에 대한 포인터가 있다.또한 바인딩 상태, 종류(멤버, 람다, 정적), 등록 해제 상태 등 다양한 값들이 관리가 된다. 그래서 왜 못하는가?Delegate는 내부적으로 함수 포인터 정보(힙 메모리) +  캡처 객체 정보로 이루.. 2025. 3. 25.