Thread: Subsequence robot(player) playings.

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    130

    Subsequence robot(player) playings.

    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.
    Last edited by Salem; 05-02-2015 at 02:24 PM. Reason: Removed all sorts of font and size abuse

  2. #2
    Registered User
    Join Date
    May 2015
    Posts
    130
    Please any help!!!

  3. #3
    Registered User talahin's Avatar
    Join Date
    Feb 2015
    Posts
    51
    Hi,
    if you want to learn writing C code please start with learning the basic syntax for C.
    Your current code looks like a mix of C and Python.

    A good place to start is here C tutorial.

    Cheers

  4. #4
    Registered User
    Join Date
    May 2015
    Posts
    130
    Quote Originally Posted by talahin View Post
    Hi,
    if you want to learn writing C code please start with learning the basic syntax for C.
    Your current code looks like a mix of C and Python.

    A good place to start is here C tutorial.


    Cheers
    It was just by a mistake because I already had a basis on python, moreover thanks for linking me the tutorial but I already read it XD

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Is your problem a matter of C syntax or of the algorithm?

    If it is C syntax, then you should learn C: if you have read a tutorial and it didn't help, then try a different tutorial, or a book, etc. Or perhaps you just need to work through the tutorial examples instead of merely reading it.

    If it is the algorithm, then you need to think about it and test your ideas with concrete examples, say outline your algorithm in pseudocode (e.g., you could use a simplified version of Python for this), or at least list some general steps/ideas in English.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2015
    Posts
    130
    Quote Originally Posted by laserlight View Post
    Is your problem a matter of C syntax or of the algorithm?

    If it is C syntax, then you should learn C: if you have read a tutorial and it didn't help, then try a different tutorial, or a book, etc. Or perhaps you just need to work through the tutorial examples instead of merely reading it.

    If it is the algorithm, then you need to think about it and test your ideas with concrete examples, say outline your algorithm in pseudocode (e.g., you could use a simplified version of Python for this), or at least list some general steps/ideas in English.
    Not really, the algorithm itself, I already learnt it or actually to be more frankly I'm still learning it. (not totally skilled in C).
    I'm willing to learn it as fully as I can.
    You could take a look to the recent thread I've posted, you'd figure exactly that what you're telling about to outline the specific issue is already taken in mind, thanks.
    Last edited by Romyo2; 05-03-2015 at 01:18 PM.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Romyo2
    Not really, the algorithm itself, I already learnt it or actually to be more frankly I'm still learning it. (not totally skilled in C).
    I'm willing to learn it as fully as I can.
    You could take a look to the recent thread I've posted, you'd figure exactly that what you're telling about to outline the specific issue is already taken in mind, thanks.
    By recent thread you mean need a help in calcaulating a -bb., right? That appears to be a different problem, so it is not relevant; your claim that it "is already taken in mind" means little: you may have it in your mind, but unless we know what you have in mind, it is difficult to try and help you beyond leading you towards a solution that you supposedly already know.

    If you have a particular algorithm in mind for this problem, then describe it here and make your best attempt at an implementation in C: we can then help you to fix your C program such that the implementation of your algorithm will work (i.e., you presumably are already able to implement your algorithm in Python, but you want to implement it in C). If you do not actually have a particular algorithm in mind, then describe the ideas that you have reaching towards coming up with such an algorithm.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    May 2015
    Posts
    130
    Quote Originally Posted by laserlight View Post
    By recent thread you mean need a help in calcaulating a -bb., right? That appears to be a different problem, so it is not relevant; your claim that it "is already taken in mind" means little: you may have it in your mind, but unless we know what you have in mind, it is difficult to try and help you beyond leading you towards a solution that you supposedly already know.

    If you have a particular algorithm in mind for this problem, then describe it here and make your best attempt at an implementation in C: we can then help you to fix your C program such that the implementation of your algorithm will work (i.e., you presumably are already able to implement your algorithm in Python, but you want to implement it in C). If you do not actually have a particular algorithm in mind, then describe the ideas that you have reaching towards coming up with such an algorithm.
    Alright!! then must be more specified, well..I will post there at need a help in calcaulating a -bb. the particular algorithm that I'm trying to code, thanks for informing me about.
    Last edited by Romyo2; 05-03-2015 at 03:05 PM.

  9. #9
    Registered User
    Join Date
    May 2015
    Posts
    130
    The problem solved-thanks anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Max SubSequence using recursion
    By Amoxaphobic in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2011, 02:46 PM
  2. finding the largest ascending subsequence..
    By transgalactic2 in forum C Programming
    Replies: 92
    Last Post: 01-21-2009, 08:57 AM
  3. Minimum Positive Subsequence Sum
    By CrazyNorman in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2008, 04:25 AM
  4. Is it a watch? Is it an MP3 player? Is it a video player?
    By twomers in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-15-2006, 10:54 PM
  5. Longest Common Subsequence
    By stimpyzu in forum Tech Board
    Replies: 4
    Last Post: 04-04-2005, 03:18 PM