1 条题解

  • -2
    @ 2022-10-30 13:41:00

    Language:cpp98

    100%AC

    #include<bits/stdc++.h>
    #define MAXNUM 25
    using namespace std;
    int myMax(int num[], int n) {
    	if (n == 0) {
    		return 0;
    	}
    	int max = num[0];
    	for (int i = 1; i < n; i++) {
    		if (max < num[i]) {
    			max = num[i];
    		}
    	}
    	return max;
    }
    int run(vector<int> v, int n) {
    	int num[MAXNUM];
    	num[n - 1] = 1;
    	for (int i = n - 2; i >= 0; i--) {
    		num[i] = 1;
    		for (int j = i + 1; j < n; j++) {
    			if (v[j] <= v[i] && (num[j] + 1) > num[i]) {
    				num[i] = num[j] + 1;
    			}
    		}
    	}
    	return myMax(num, n);
    }
    
    int main(void) {
    	vector<int> v;
    	int n = 0;
    	cin >> n;
    	for (int i = 0; i < n; i++) {
    		int temp = 0;
    		cin >> temp;
    		v.push_back(temp);
    	}
    	int result = run(v, n);
    	cout << result << endl;
    	return 0;
    }
    

    信息

    ID
    791
    时间
    1000ms
    内存
    16MiB
    难度
    8
    标签
    递交数
    269
    已通过
    42
    上传者