由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一个DP的题
相关主题
DP interview question最新两个面试题目
Fibonacci number interview questions?发Facebook intern面经
Google onsite问题ComputerScience里面的经典问题
Interview Questions for an investment bankGoogle取硬币的题
good way to solve this problem?all possible picking from n sets
career cup 上9.4题答案是否正确print bst in level order dfs为什么是O(N)不应该是O(N^2)吗?
有人做过codility.com的题吗?内推: Job opening @ Intel Santa Clara
问道题继续贴几个题目
相关话题的讨论汇总
话题: vi话题: vj话题: dp话题: sequence话题: card
进入JobHunting版参与讨论
1 (共1页)
v******a
发帖数: 54
1
Consider the following game. 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.
Give an O(n*n) algorithm to compute an optimal strategy for the first player
. Given th
h**6
发帖数: 4160
2
生成一个n*n的矩阵,里面全是0和1,表示剩余部分的开始结束位置分别为i和j时从前
面还是后面取。
A*********r
发帖数: 564
3
令F(i,j)表示从范围i..j中取头或尾能得到的最大value,
那么
F(i,j)=max { min {F(i+1,j-1), F(i+2,j)}+Vi, min {F(i+1,j-1), F(i,j-2))}+Vj }
第一项是取了i的话,至少能够得到的值(对手可能取剩下的i+1或者j),第二项
是取了j的话,至少能够得到的值。。
下面这个link的第10道题,基本上一样吧。。
http://people.csail.mit.edu/bdean/6.046/dp/

denominations
player

【在 v******a 的大作中提到】
: Consider the following game. 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.
: Give an O(n*n) algorithm to compute an optimal strategy for the first player
: . Given th

p********7
发帖数: 549
4
正解

}

【在 A*********r 的大作中提到】
: 令F(i,j)表示从范围i..j中取头或尾能得到的最大value,
: 那么
: F(i,j)=max { min {F(i+1,j-1), F(i+2,j)}+Vi, min {F(i+1,j-1), F(i,j-2))}+Vj }
: 第一项是取了i的话,至少能够得到的值(对手可能取剩下的i+1或者j),第二项
: 是取了j的话,至少能够得到的值。。
: 下面这个link的第10道题,基本上一样吧。。
: http://people.csail.mit.edu/bdean/6.046/dp/
:
: denominations
: player

m**q
发帖数: 189
5
这样行不行?
因为目的是想让自己多得分,对方少得分,既然每人取n/2个,
相当于想办法使得自己得分比对方得分多得越多越好。
设f(i,j)表示范围i...j中所得获得的最大分差(自己总分 - 对方总分)
f(i,j) = max { f(i+1,j-1) + Vi - Vj,
f(i+2,j) + Vi - Vi+1,
f(i+1,j-1) + Vj - Vi,
f(i,j-2) + Vj - Vj-1 }
我觉得这个的最优解应该和你的是一样的。

2))}+Vj }

【在 A*********r 的大作中提到】
: 令F(i,j)表示从范围i..j中取头或尾能得到的最大value,
: 那么
: F(i,j)=max { min {F(i+1,j-1), F(i+2,j)}+Vi, min {F(i+1,j-1), F(i,j-2))}+Vj }
: 第一项是取了i的话,至少能够得到的值(对手可能取剩下的i+1或者j),第二项
: 是取了j的话,至少能够得到的值。。
: 下面这个link的第10道题,基本上一样吧。。
: http://people.csail.mit.edu/bdean/6.046/dp/
:
: denominations
: player

1 (共1页)
进入JobHunting版参与讨论
相关主题
继续贴几个题目good way to solve this problem?
请教一道面试题career cup 上9.4题答案是否正确
新鲜C3 energy面经有人做过codility.com的题吗?
一道google 题,谁给翻译一下意思,多谢。问道题
DP interview question最新两个面试题目
Fibonacci number interview questions?发Facebook intern面经
Google onsite问题ComputerScience里面的经典问题
Interview Questions for an investment bankGoogle取硬币的题
相关话题的讨论汇总
话题: vi话题: vj话题: dp话题: sequence话题: card