Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Backtracking in C.

Backtracking in C.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Washiko
    wrote on last edited by
    #1

    Programming.. Backtracking.
    I need help with backtracking question.
    In an election, five parties won and got
    A 20
    B 14
    C 30
    D 16
    E 40

    In order to rule, a coalition of More than 60 must be negotiated. But we have restrictions:
    A does not sit with D
    C does not sit with E

    A B  C  D E
    

    A. 1 1 1 0. 1
    B. 1 1. 1 1. 1
    C. 1 1. 1 1. 0
    D 0 1. 1 1. 1
    E. 1. 1. 0. 1. 1

    The function should return the number of possible coalitions.. Which is 3.
    As soon as the coalition is formed, no need to add more parties.
    A + E + B is not valid

    L S 2 Replies Last reply
    0
    • W Washiko

      Programming.. Backtracking.
      I need help with backtracking question.
      In an election, five parties won and got
      A 20
      B 14
      C 30
      D 16
      E 40

      In order to rule, a coalition of More than 60 must be negotiated. But we have restrictions:
      A does not sit with D
      C does not sit with E

      A B  C  D E
      

      A. 1 1 1 0. 1
      B. 1 1. 1 1. 1
      C. 1 1. 1 1. 0
      D 0 1. 1 1. 1
      E. 1. 1. 0. 1. 1

      The function should return the number of possible coalitions.. Which is 3.
      As soon as the coalition is formed, no need to add more parties.
      A + E + B is not valid

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This is a mathematical/logic question, which you need to solve first. Once you have done that then writing the code should be straightforward.

      1 Reply Last reply
      0
      • W Washiko

        Programming.. Backtracking.
        I need help with backtracking question.
        In an election, five parties won and got
        A 20
        B 14
        C 30
        D 16
        E 40

        In order to rule, a coalition of More than 60 must be negotiated. But we have restrictions:
        A does not sit with D
        C does not sit with E

        A B  C  D E
        

        A. 1 1 1 0. 1
        B. 1 1. 1 1. 1
        C. 1 1. 1 1. 0
        D 0 1. 1 1. 1
        E. 1. 1. 0. 1. 1

        The function should return the number of possible coalitions.. Which is 3.
        As soon as the coalition is formed, no need to add more parties.
        A + E + B is not valid

        S Offline
        S Offline
        Stefan_Lang
        wrote on last edited by
        #3

        Washiko wrote:

        A + E + B is not valid

        I don't see why not. Above the condition was stated that

        Washiko wrote:

        a coalition of More than 60 must be negotiated

        which means neither A+E nor A+B or B+E would be enough - all three are needed to get more than 60. As for your program, if you don't know what backtracking means, look up recursion and backtracking. There's nothing difficult about coding these concepts in C. If you do know what it means, write a program and, if at any point you're stuck, show the code you're stuck with. We don't write full programs for other people on request. If it's homework, we'd do you a disfavor by destroying a chance for you to learn. If it's work, you'd get paid, and you can't expect from others to do that work for you without payment. If it's a contest, it's part of the contest to find out how to write the program - if others do it for you it tells nothing about your skills, and it would be unfair to the other contestants.

        GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups