由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 算法题目一问
相关主题
两种DP转一些我blog上以前总结题目的日记(三)
请教一个面试问题,careercup上的bloomberg相关的面试题
问道Google题目C++ Q35: sizeof() (B20_20)
究竟什么定义了DPC++ Q78: about sizeof
问个白痴问题,DP到底算不算递归?Non-recursive permutation
topcoder- strange country problem.C++ coding practice 一问
用 c 实现的字符串 permutation,求批评指点再来讨论一个题!
请教一个题,不太容易,要O(n)Recursion算法复杂度计算一问
相关话题的讨论汇总
话题: inf话题: donate话题: int话题: max话题: ith
进入JobHunting版参与讨论
1 (共1页)
n*******s
发帖数: 482
1
People say this is a typical DP problem, fundamental level.
m*****f
发帖数: 1243
2
topcoder题目? 不是有别人做的代码可以看吗
k***e
发帖数: 556
3
看到这么长的题目 我一般放弃 都没耐心读完他

【在 m*****f 的大作中提到】
: topcoder题目? 不是有别人做的代码可以看吗
g*******y
发帖数: 1930
4
假设子问题针对第1号到第i号(前i个人),但是首尾不相连(1号和i号不是邻居):
需要知道子问题里第i号是否要donate
当做到最后一个人(第n号)的时候,因为最后一个人既跟n-1号人,又跟1号相邻,那么就需要知道子问题里面第1号人是否donate
也就是说,子问题的state需要几个参数:
1个bit来表示第一个人是否donate
1个bit来表示最后一个人是否donate
1个int i来表示从1号到第i号人的子问题
也就是说,用一个数组:
a[2][2][n]来保存每个子问题的解。
定义好子问题后,写出状态转移方程,然后一直算到倒数第二个人结束。第n个人单独处理一下
n*******s
发帖数: 482
5
just wake up and consider it again:
Trying to solve it in this way:
original problem: a1, a2, ....ai, ...an-1, an
subproblem : a1, a2, ... ai
Define array: L[2][n]
L[0][i] --> the max donation where the ith neighbor won't donate
L[1][i] -->the max donation where the ith neighbor will donate
Recursive relation:
L[0][i+1] = max {L[0][i], L[1][i]}
L[1][i+1] = L[0][i] + a[i]
However, during this extension, we don't consider the head/tail collision, but this will be problem. So at the final st
g*******y
发帖数: 1930
6
how about
note: inf = infinity
numbers: inf, inf/2,.....10,inf*0.75
all your L[0][] L[1][] will select the first number:"inf"
when it comes to the last number "inf*0.75":
which number to sacrifice?
obviously the answer should abandon the first "inf", but if you abandon the first number, your L[][] result will become useless
this is exactly what I meant in my post:
You don't define a "state"(i.e,subproblem) well enough if you don't specify whether the first number is chosen or not.

【在 n*******s 的大作中提到】
: just wake up and consider it again:
: Trying to solve it in this way:
: original problem: a1, a2, ....ai, ...an-1, an
: subproblem : a1, a2, ... ai
: Define array: L[2][n]
: L[0][i] --> the max donation where the ith neighbor won't donate
: L[1][i] -->the max donation where the ith neighbor will donate
: Recursive relation:
: L[0][i+1] = max {L[0][i], L[1][i]}
: L[1][i+1] = L[0][i] + a[i]

n*******s
发帖数: 482
7
l's inital value would be
L[0][0] = 0
L[1][0] = a[0]
since, L[0][i] means the possible max if the ith does not donate
L[1][i] means the possible max if the ith does donate
Here is the code:
int a[] = { 94, 40, 49, 65, 21, 21, 106, 80, 92, 81, 679, 4, 61, 6, 237
, 12, 72, 74, 29, 95, 265, 35, 47, 1, 61, 397, 52, 72, 37, 51, 1, 81, 45,
435, 7, 36, 57, 86, 81, 72 };
int size = sizeof(a)/sizeof(int);
int l[2][size];
int m[size];
int type=0;
int i =0, j=0, max=0;
m
g*******y
发帖数: 1930
8
have you tried my test case?
inf, inf*0.5, ...(normal numbers),inf*0.7
you can use 9999999 as inf.

237

【在 n*******s 的大作中提到】
: l's inital value would be
: L[0][0] = 0
: L[1][0] = a[0]
: since, L[0][i] means the possible max if the ith does not donate
: L[1][i] means the possible max if the ith does donate
: Here is the code:
: int a[] = { 94, 40, 49, 65, 21, 21, 106, 80, 92, 81, 679, 4, 61, 6, 237
: , 12, 72, 74, 29, 95, 265, 35, 47, 1, 61, 397, 52, 72, 37, 51, 1, 81, 45,
: 435, 7, 36, 57, 86, 81, 72 };
: int size = sizeof(a)/sizeof(int);

1 (共1页)
进入JobHunting版参与讨论
相关主题
Recursion算法复杂度计算一问问个白痴问题,DP到底算不算递归?
做topcoder竞赛的同学,欢迎加入Topcodes俱乐部topcoder- strange country problem.
求推荐学习recursive 算法的资料用 c 实现的字符串 permutation,求批评指点
求教一个combination的问题,求好方法请教一个题,不太容易,要O(n)
两种DP转一些我blog上以前总结题目的日记(三)
请教一个面试问题,careercup上的bloomberg相关的面试题
问道Google题目C++ Q35: sizeof() (B20_20)
究竟什么定义了DPC++ Q78: about sizeof
相关话题的讨论汇总
话题: inf话题: donate话题: int话题: max话题: ith