2281번 - 데스노트
완료 코드가 아니라 중간 코드이긴 한데...
예제를 기준으로 출력했을 때
11 20 7 4 2 3 2 5 1 12 7 5 6
52~55줄의
if (remain >= names[pos] + 1) { dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line, remain - (names[pos] + 1))); }dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line + 1, m - names[pos]) + remain * remain);
이 부분을 이렇게 설정하고 돌리면 답이 61이 나옵니다.
하지만,
이것을 고쳐서
dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line + 1, m - names[pos]) + remain * remain);
if (remain >= names[pos] + 1) { dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line, remain - (names[pos] + 1)));}
로 바꿔서 돌리게 되면 출력이 1이 나오게 됩니다.
순서라곤 해도 아직 dp에 따라 재귀를 반복 안 하게 설정 한 것도 아니니 똑같은 값인 61이 나와야 할거 같은데
어째서 이런 현상이 나오는지 이해가 되지 않습니다.
혹시 이 부분에 대한 지식을 나눠 주실 수 있으시면 감사드리겠습니다.
댓글을 작성하려면 로그인해야 합니다.
grapecw 3년 전
완료 코드가 아니라 중간 코드이긴 한데...
예제를 기준으로 출력했을 때
52~55줄의
if (remain >= names[pos] + 1) {
dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line, remain - (names[pos] + 1)));
}
dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line + 1, m - names[pos]) + remain * remain);
이 부분을 이렇게 설정하고 돌리면 답이 61이 나옵니다.
하지만,
이것을 고쳐서
dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line + 1, m - names[pos]) + remain * remain);
if (remain >= names[pos] + 1) {
dp[line][pos] = Math.min(dp[line][pos], getBlankCnt(pos + 1, line, remain - (names[pos] + 1)));
}
로 바꿔서 돌리게 되면 출력이 1이 나오게 됩니다.
순서라곤 해도 아직 dp에 따라 재귀를 반복 안 하게 설정 한 것도 아니니 똑같은 값인 61이 나와야 할거 같은데
어째서 이런 현상이 나오는지 이해가 되지 않습니다.
혹시 이 부분에 대한 지식을 나눠 주실 수 있으시면 감사드리겠습니다.