这个不就是叠罗汉嘛我怎么只过了百分50% int main() { int n; cin >> n; if (n <= 0) { cout << 0 << endl; return 0; } int tmp; vector<vector<int>> arr; for (int i = 0; i < n; i++) { arr.push_back(vector<int>()); } for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> tmp; arr[i].push_back(tmp); } } vector<int> res(n, 0); for (int i = 0; i < n; ++i) { swap(arr[i][0], arr[i][2]); res[i] = arr[i][2]; } sort(arr.begin(), arr.end()); int maxlen = arr[0][2]; for (int i = 1; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (arr[i][0] < arr[j][0] && arr[i][1] < arr[j][1]) { res[i] = max(res[j]+arr[i][2], res[i]); } } maxlen = max(maxlen, res[i]); } std::cout << maxlen << std::endl; return 0; }
点赞 评论

相关推荐

牛客网
牛客企业服务