Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 1e5 + 10;
- const int INF = 2e9 + 5;
- int n;
- int arr[maxn];
- int dp[maxn]; /*dp[i] znaci deka najdolgata rastecka podniza do pozicija i e ednakva na dp[i]*/
- int main(){
- int t;
- cin >> t;
- while(t--){
- cin >> n;
- for(int i = 0; i < n; ++i) {
- cin >> arr[i];
- dp[i] = 1;
- }
- for(int at = 0; at < n; ++at) {
- for(int nxt_index = at + 1; nxt_index < n; ++nxt_index) {
- if(arr[at] <= arr[nxt_index]) {
- dp[nxt_index] = max(dp[nxt_index], dp[at] + 1);
- }
- }
- }
- int ret = 0;
- for(int i = 0; i < n; ++i) {
- ret = max(ret, dp[i]);
- }
- cout << ret << endl;
- }
- return 0;
- }
- /*
- [10 9 2 5 3 7 101 18]
- rec(0) -> rec(6)
- rec(0) -> rec(7)
- rec(1) -> rec(6)
- rec(1) -> rec(7)
- rec(2) -> rec(3) -> rec(5) -> rec(6)
- rec(2) -> rec(3) -> rec(5) -> rec(7)
- rec(2) -> rec(4) -> rec(5) -> rec(6)
- rec(2) -> rec(4) -> rec(5) -> rec(7)
- .
- .
- .
- */
Advertisement
Add Comment
Please, Sign In to add comment