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

  • Home
  • SEARCH
  • 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 7743035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:25:47+00:00 2026-06-01T09:25:47+00:00

I was practicing the problem on Algorithm games , I tried the following problem

  • 0

I was practicing the problem on Algorithm games , I tried the following problem but couldn’t find the efficient way to do it::

So can you please help me.Here is the problem.

This is the exact link::
http://community.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm228

  • 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-01T09:25:48+00:00Added an answer on June 1, 2026 at 9:25 am

    I assume that you would like to solve this one by yourself, so I will give you a hint: this problem has optimal substructure.

    Imagine that you have both solutions for N-1 coins (without the leftmost one and without the rightmost one). Would it be easy to calculate a solution for N coins then?

    You can use two related techniques to exploit this property – dynamic programming and its subtype called memoization. The idea is to store a solution to each sub-problem with L coins missing from the left and R coins missing from the right (use an NxN array for it). Before solving a sub-problem, check the array to see if you’ve already solved it. You would need to solve at most N^2/2 subproblems to arrive at a solution.

    Here is pseudocode for a memoized solution:

    // solved[L][R] array contains the highest value a player could get
    // on a subproblem where L coins are missing from the left
    // and R are missing from the right of the original sequence on his move
    int solved[N][N] // initialize each element to -1.
    int coins[N]     // initialize with coin values 
    
    int solve(int L, int R) {
        if (L+R == N) return 0; // No coins remain
        if (solved[L][R] >= 0) return solved[L][R];
        int remaining = sum(coins from L to R)
        int takeLeft = remaining - solve(L+1, R);
        int takeRight = remaining - solve(L, R+1);
        int result = max(takeLeft, takeRight);
        solved[L][R] = result;
        return result;
    }
    
    main() {
        int alice = solve(0, 0);
        int bob = sum(coins) - alice;
    }
    

    I remember TopCoder running this problem some time in early 2005 or 2006, but I do not remember enough details to search their problem archive.

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

Sidebar

Related Questions

I was practicing the dynamic programming problem on SPOJ. But I have no idea
I am practicing StringToByteArray() on VS2005. But throw exception. Could you please tell me
I am practicing DOM Scripting (no real-life problem but rather practice and theory, I
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
Every time I start a hard problem and if can not figure out the
I was practicing SRM Problems in Topcoder.I came across this problem Problem Statement: Today
Been practicing with those system calls, but I stucked into this code: #include <stdio.h>
I am practicing with PHP and AJAX but I have some problems! I'm trying
I am actually practicing Greedy Algorithms and There is a problem on topcoder.. So
I'm practising POSIT algorithm in OpenCV, following the tutorial http://opencv.willowgarage.com/wiki/Posit My goal is to

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.