由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一下那个paint house的DP题
相关主题
问一个题 house paint请教实习的one time house allowance
how many ways can you paint a cube using 3 colors?[合集] 报个offer,请大家帮忙看看 (转载)
请教一道组合题跟contract house签的工作跟和正式公司签的工作有什么区别
cube用三种颜色paint的方法是多少种?在Atlanta, $94k for senior software engineer 这个工资怎样?
google 一道dp 题关于 rental compensation
How far will my salary go in another city?Amazon, CISCO or Bloomberg offer
paint house (leetcode), 如果K colors, M个houses在一个环上应该怎么做?什么是open house interview?
问个facebook 面试题请问这offer里这两句是什么意思
相关话题的讨论汇总
话题: houses话题: fun话题: paint话题: cost话题: house
进入JobHunting版参与讨论
1 (共1页)
s***f
发帖数: 226
1
There are a row of houses, each house can be painted with three colors red,
blue and green. The cost of painting each house with a certain color is
different. You have to paint all the houses such that no two adjacent houses
have the same color. You have to paint the houses with minimum cost. How
would you do it?
r*********g
发帖数: 67
2
一排房子,难道不是两种最便宜的颜色轮流漆……?
o***g
发帖数: 2784
3
假设前面N个已经刷好了,第N+1个,不能和第N个同颜色,就剩俩颜色了,选便宜的那个
第一个就三个里面选最便宜的。

,
houses

【在 s***f 的大作中提到】
: There are a row of houses, each house can be painted with three colors red,
: blue and green. The cost of painting each house with a certain color is
: different. You have to paint all the houses such that no two adjacent houses
: have the same color. You have to paint the houses with minimum cost. How
: would you do it?

g*********e
发帖数: 14401
4
minCost(first i houses, i th house with color x)

,
houses

【在 s***f 的大作中提到】
: There are a row of houses, each house can be painted with three colors red,
: blue and green. The cost of painting each house with a certain color is
: different. You have to paint all the houses such that no two adjacent houses
: have the same color. You have to paint the houses with minimum cost. How
: would you do it?

o***g
发帖数: 2784
5
这个还真有问题,比如
R G B
1 10 100 1000
2 1 1000 10000
第一个选了10,第二个就得选1000,结果是1010
其实答案应该是第一个选100,第二个选1,结果是101

那个

【在 o***g 的大作中提到】
: 假设前面N个已经刷好了,第N+1个,不能和第N个同颜色,就剩俩颜色了,选便宜的那个
: 第一个就三个里面选最便宜的。
:
: ,
: houses

R******9
发帖数: 267
6
use a 3*N matrix.
fun('R', i) = cost('R', i) + min(fun('B', i-1), fun('G', i-1));
fun('G', i) = cost('G',i) + min(fun('R', i-1), fun('B', i-1));
fun('B', i) = cost('B', i) + min(fun('R',i-1), fun('G', i-1));

【在 o***g 的大作中提到】
: 这个还真有问题,比如
: R G B
: 1 10 100 1000
: 2 1 1000 10000
: 第一个选了10,第二个就得选1000,结果是1010
: 其实答案应该是第一个选100,第二个选1,结果是101
:
: 那个

1 (共1页)
进入JobHunting版参与讨论
相关主题
请问这offer里这两句是什么意思google 一道dp 题
想咨询一下Milpitas, CA 的情况How far will my salary go in another city?
是不是失业率又上升啦?paint house (leetcode), 如果K colors, M个houses在一个环上应该怎么做?
IBM watson intern的housing问题请教问个facebook 面试题
问一个题 house paint请教实习的one time house allowance
how many ways can you paint a cube using 3 colors?[合集] 报个offer,请大家帮忙看看 (转载)
请教一道组合题跟contract house签的工作跟和正式公司签的工作有什么区别
cube用三种颜色paint的方法是多少种?在Atlanta, $94k for senior software engineer 这个工资怎样?
相关话题的讨论汇总
话题: houses话题: fun话题: paint话题: cost话题: house