-
Notifications
You must be signed in to change notification settings - Fork 0
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
[동적 계획법] 4월 4일 #8
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "03\uC6D4-29\uC77C---\uB3D9\uC801-\uACC4\uD68D\uBC95"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
선택 3문제 확인했습니다!
문제를 너무 잘 풀어주셔서 따로 피드백 드릴 내용이 없었습니다!
주석도 꼼꼼하게 잘 작성해주셔서 너무 좋았습니다 🤗🤗!!
지금 상태로 머지해주셔도 좋고, 코멘트 반영해주신 후 저 리뷰어로 불러주셔도 좋습니다!! 감사합니다🥰🥰
for (int i = 1; i < n; i++) { | ||
int m = 0; | ||
for (int j = 0; j < i; j++) { //i번 앞 원소들 순회 | ||
if (a[j] < a[i]) { //증가하는 수열이 되면 | ||
m = max(m, dp[j]); //길이 최댓값 업데이트 | ||
} | ||
} | ||
dp[i] = m + 1; //구한 길이에 해당 원소 포함되니 + 1 | ||
} | ||
|
||
// for(int i: dp){ | ||
// cout<<i<<' '; | ||
// } | ||
|
||
//출력 | ||
cout << *max_element(dp.begin(), dp.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p2.
증가하는 수열인 것을 확인하고 m을 갱신해주시며 dp에 저장해주셨군요! 좋아요!!🤗🤗
그런데, 증가하는 수열인 것을 확인했다면 m에 저장해놓는 것보다 바로 dp를 갱신해주는 건 어떨까요?
dp의 포인트는 각 인덱스마다의 값을 최댓값으로 (혹은 문제에 따라 최솟값) 갱신해주는 것입니다!
따라서, dp의 맨 마지막 인덱스엔 구하려는 최댓값이 자연스럽게 남아있게 되는 거죠! max_element
으로 가장 큰 답을 구해주지 않아도 바로 참조가능하죠.🤗🤗
강의자료를 참고하시면 더 이해가 잘 되실 것 같습니다!
dp[1] = 1; | ||
dp[2] = 3; //dp[3] = 3 + (1+1) = 5 | ||
for (int i = 3; i <= n; i++) { | ||
dp[i] = (dp[i - 2] * 2 + dp[i - 1]) % 10007; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3. 10007 은 상수로 선언해주시는 건 어떨까요?? 🤗🤗
내용 & 질문
<기존 제출>