강의

멘토링

커뮤니티

Inflearn Community Q&A

baljang1058's profile image
baljang1058

asked

[MMORPG Game Development with C++ and Unreal Engine Series] Part 3: Data Structures and Algorithms

Sample Problem : LIS

코드에선 int cache[100] 없데이트가 안되고 있는거죠?

Written on

·

291

0

int cache[100] 이 -1로 초기화 되고 업데이트 되는 부분이 없으니

// 구하기

for (int next = pos + 1; next < seq.size(); next++)

{

if (seq[pos] < seq[next])

ret = max(ret, 1 + LIS(next));

               cache[pos] = ret;

}

 

이렇게 코드를 추가해 주면 cache를 사용하게 되는거죠?

기술면접

Answer 1

2

Rookiss님의 프로필 이미지
Rookiss
Instructor

int& ret = cache[pos];

여기서 &이 붙은 것에 유의하세요!
따라서 실제로 ret를 건드리면, 원본 cache를 건드리게 되니
업데이트를 하고 있는 것입니다.

baljang님의 프로필 이미지
baljang
Questioner

그렇군요. 강의에서도 말씀해 주신 부분인데 놓쳤었네요. 감사합니다. :)

baljang1058's profile image
baljang1058

asked

Ask a question