File size: 440 Bytes
3805fe5
bff4ec7
 
3805fe5
 
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3805fe5
bff4ec7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int maxSumIncreasingSequence(int *nums, int numsSize)

{
  int dp[100000];

  dp[0] = nums[0];
  int ans = nums[0];

  for (int i = 1; i < numsSize; ++i) {
    dp[i] = nums[i];

    for (int j = 0; j < i; ++j) {
      if (nums[j] < nums[i]) {
        int candidate = dp[j] + nums[i];
        if (candidate > dp[i]) {
          dp[i] = candidate;
        }
      }
    }

    if (dp[i] > ans) {
      ans = dp[i];
    }
  }

  return ans;
}