Skip to content

A dealer produces a sequence s1, …, sn of .cards, face-up, where each card si has a value vi. Then two players take turns picking a card from the sequence, but can only pick the first or the last card of the (remaining) sequence. The goal is to collect cards of largest total value.

Notifications You must be signed in to change notification settings

mehboobali98/Card-Game-DP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Card Game Dynamic Programming

Problem Statement

A dealer produces a sequence s1, …, sn of .cards, face up, where each card si has a value vi. Then two players take turns picking a card from the sequence, but can only pick the first or the last card of the (remaining) sequence. The goal is to collect cards of largest total value. (For example, you can think of the cards as bills of different denominations). Assume n is even.

Algorithm

The detailed algorithm is discussed in the Algorithm.pdf file.

Approach

The algorithm to solve the problem has been implemented in three ways:

  • recursive
  • top-down
  • bottom-up (Dynamic Programming)

Time Complexity

The time complexity of the dynamic programming solution is: O(N^2)

Directory Structure

📦Card-Game-DP ┣ 📜main.cpp ┗ 📜README.md

About

A dealer produces a sequence s1, …, sn of .cards, face-up, where each card si has a value vi. Then two players take turns picking a card from the sequence, but can only pick the first or the last card of the (remaining) sequence. The goal is to collect cards of largest total value.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published