Hello, I'm heading for scripting this problem which is:
given an array all of whose elements are positive numbers, that I must find the longest subsequence that's ofcourse monotonically increasing(its "Sequences", a term in mathematic) constraints that no 2 numbers in the sequence should be adjacent in the array and equivalent. So lets say a random array(given by the user) is 100 1 2 3 4 5 , the output should return a long sub-sequence(math term) could be found in this array(must preserving on the arranging), which is in this statement : 1 2 3 4 5.
another example : arr:100 10 5 20 4 30, the return should be the longest increasing subsequence: 10 20 30.
I'm a new programmer in C (has fairly basis on python), I tried coding by using all possible information and functions that I know in C but unfortunately the things just went wrong, I think a real programmer that had been treating many codes could have and instruct me better than struggling by myself with no efforts.
By the way, the code that I've scripted is:
Code:
#include<stdio.h>
function M_SUM(n)
return sequence_sub(M_sequence(n, true), M_sequence(n, false))
function M_SUM(n, flag)
if n == 0
then return0 elseif n == 1 return flag ? i[0] : 0} else
{
if flag
then return MAX(M_sequence(n - 2, true) + i[n - 1],
M_sequence(n - 2, false) + MAX(i[n - 1], i[n - 2]))
else
return sequence_sub(M_sequence(n - 2, false) + i[n - 2],
M_sequence(n - 2, true))
}
i think using dynamic programming is a better way for this case, but as I haven't treated with dynamic programming. in c programming then its hard for me and I need a help for coding this code, a hint script for what doing exactly.
the code isn't compling at all even if I enter any sequence.
thanks.