Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:54:17+00:00 2026-06-15T12:54:17+00:00

This is a simple game: There is a set, A={a1,…,an}, the opponents can choose

  • 0

This is a simple game:
There is a set, A={a1,…,an}, the opponents can choose one of the first or last elements of set, and at the end the one who collect bigger numbers wins. Now say each participants dose his best, what I need to do is write a Dynamic algorithm to estimate their score.
any idea or clue is truly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:54:18+00:00Added an answer on June 15, 2026 at 12:54 pm

    EXAMPLE CODE

    Here is Python code to compute the optimal score for first and second players.

    A=[3,1,1,3,1,1,3]
    
    cache={}
    def go(a,b):
        """Find greatest difference between player 1 coins and player 2 coins when choosing from A[a:b]"""
        if a==b: return 0 # no stacks left
        if a==b-1: return A[a] # only one stack left
        key=a,b
        if key in cache:
            return cache[key]
    
        v=A[a]-go(a+1,b) # taking first stack
        v=max(v,A[b-1]-go(a,b-1)) # taking last stack
    
        cache[key]=v
        return v
    
    v = go(0,len(A))
    n=sum(A)
    print (n+v)/2,(n-v)/2
    

    COUNTEREXAMPLE

    Note that the code includes a counter example to one of the other answers to this question.

    Consider the case [3,1,1,3,1,1,3].

    By symmetry, the first players move always leaves the pattern [1,1,3,1,1,3].

    For this the sum of even elements is 1+3+1=5, while the sum of odd is 1+1+3=5, so the argument is that from this position the second player will always win 5, and the first player will always win 5, so the first player will win (as he gets 5 in addition to the 3 from the first move).

    However, this logic is flawed because the second player can actually get more.

    First player takes 3, leaves [1,1,3,1,1,3] (only choice by symmetry)
    Second player takes 3, leaves [1,1,3,1,1]
    First player takes 1, leaves [1,3,1,1] (only choice by symmetry)
    Second player takes 1, leaves [1,3,1]
    First player takes 1, leaves [3,1] (only choice by symmetry)
    Second player takes 3, leaves [1]
    First player takes 1
    

    So overall first player gets 3+1+1+1=6, while second gets 3+1+3=7 and second player wins.

    The flaw is that although it is true that the second player can play such that they will win all even or all odd positions, this is not optimal play and they can actually do better than this in some cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this as a simple dice game. It works as I want except
I've built a simple snake game that uses a Main class (this is my
i added sprite to scene by this tutorials : http://www.raywenderlich.com/9743/how-to-create-a-simple-2d-iphone-game-with-opengl-es-2-0-and-glkit-part-1 but i have bad
Simple question but I got a headache to solve this game. Example regex. [a-zA-Z0-9\s]
Hopefully this is a quick question. I'm making a simple rock paper scissors game.
I'm trying to create this simple game but I'm having trouble. Here's the code,
I am working on a simple platform game in HTML5/Canvas/Javascript/jQuery. You can see it
This simple query session = com.jthink.songlayer.hibernate.HibernateUtil.getSession(); Query q = session.createQuery(recNo from SongChanges); giving this
This simple script should theoretically check the form for errors and then print any
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.