Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用递归为啥总是wa呢。。。哪位大神可以提供数据?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator