Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Feb 3, 2025

🧷 문제 링크

https://www.acmicpc.net/problem/2758

🧭 풀이 시간

10분

👀 체감 난이도

✏️ 문제 설명

$1$부터 $m$까지의 수 중 $n$개의 수를 고르는데, 이전에 고른 수의 2배 이상인 수만 고른다고 합니다.
수를 고르는 방법의 수를 구해야 합니다.

🔍 풀이 방법

$dp[n][m]$$n$개를 골랐고, 마지막에 고른 수가 $m$일 때의 경우의 수라고 합시다.
$dp[n][m] = dp[n-1][1] + \cdots + dp[n-1][\lfloor \frac{m}{2} \rfloor]$ 와 같은 식이 성립합니다.

정의를 살짝 바꿔서, $n$개를 골랐고 마지막에 고른 수가 $m$ 이하일 때의 경우의 수라고 합시다.
$dp[n][m] = dp[n][m-1] + dp[n-1][m/2]$로 식을 간단하게 줄일 수 있습니다.

⏳ 회고

테스트 케이스의 수가 주어지지 않아서 원래 식인 $O(NM^2)$로 풀게 되면 시간에 걸릴 것 같아 식 최적화를 떠올리게 되었습니다

@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Feb 3, 2025
@oncsr oncsr self-assigned this Feb 3, 2025
@ShinHeeEul ShinHeeEul merged commit 227f8ff into main Feb 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants