LIS 질문입니다

  • User Avatar
    ieehyeon

    스택 오버플론가 뜨면서 런타임 오류가 생기네요
    그래서 배열을 약간 키워줬는데도 오류가 생깁니다. 왜 그런걸까요?
    고수님들 가르쳐주세요
    ~~~ c++
    #include
    #include
    #include
    #include

    using namespace std;

    int t, n, a;

    int cache[101], S[100];

    int lis3(int start) {
    int& ret = cache[start+1];

    if (ret != -1) return ret;
    
    ret = 1;
    for (int next = start + 1; next < n; next++) {
        if (start==-1||S[start] < S[next]) ret = max(ret, lis3(next) + 1);
    }
    return ret;
    

    }

    int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> n;
    
        memset(S, -1, sizeof(S));
        memset(cache, -1, sizeof(cache));
    
        for (int j = 0; j < n; j++) {
            cin >> S[j];
    
        }
    
        cout << lis3(-1)-1<<endl;
    }
    

    }
    ~~~


    7년 전
1개의 댓글이 있습니다.
  • User Avatar
    SteelFox

    N (<= 500)


    7년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.