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 |
为什么加了//后面的这个&& num_val[j] > temp, 就不正确了呢? 难道能找到比该数小又比它长的?#include <iostream> using namespace std; int main() { int N; int *num_val, *num_sum; int i; while(cin >> N) { num_val = new int[N]; num_sum = new int[N]; for(i = 0; i < N; i++) { scanf("%d", &num_val[i]); num_sum[i] = 1;//置一 } int temp, max; for(i = 1; i < N; i++) { max = 0; temp = 0; for(int j = i-1; j >= 0; j--) { if(num_val[j] < num_val[i] ) //&& num_val[j] > temp) ///////疑问! { if(num_sum[j] > max) { temp = num_val[j];//WA是用于标记的数 max = num_sum[j]; } } } num_sum[i] += max;//算出该数为结尾的最长子序列 } max = 0; /* for(i = 0 ; i < N; i++) { cout << num_sum[i] << " "; } cout << endl;//观看 */ for(i=0; i < N; i++) { if(num_sum[i] > max) max = num_sum[i]; }//搜出最大的子序列数 cout << max << endl; } delete[]num_val; delete[]num_sum; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator