Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用递归为啥总是wa呢。。。哪位大神可以提供数据?

Posted by fakeID at 2012-12-08 19:23:01 on Problem 2533 and last updated at 2012-12-08 19:24:26
#include <iostream>
using namespace std;


int longestOrderedSubseq(int l, int r, int array[], int biggestSoFar) {
    if (l > r) return 0;
    int out = 0;
    for (int i = l; i <= r; ++i) {
        if (array[i] > biggestSoFar){
            int tmp = longestOrderedSubseq(i+1, r, array, array[i]) + 1;
            out = out < tmp ? tmp : out;
        }
        else {
            int tmp = longestOrderedSubseq(i+1, r, array, biggestSoFar);
            out = out < tmp ? tmp : out;
        }
    }
    return out;
}

int main()
{
    int n;
    cin >> n;
    int array[1001];
    for (int i = 0; i < n; ++i) cin >> array[i];
    cout << longestOrderedSubseq(0, n-1, array, 0) << endl;
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator