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? Note: Painting house-1 with red costs different from painting house-2 with red. The costs are different for each house and each color.
cost(i,b)=min(cost(i-1,g),cost(i-1,r))+cost of painting i as b;
cost(i,g)=min(cost(i-1,b),cost(i-1,r))+cost of painting i as g;
cost(i,r)=min(cost(i-1,g),cost(i-1,b))+cost of painting i as r;
finally min(cost(N,b),cost(N,g),cost(N,r)) is the ans
public static int minCost(int n, int[][] cost) { int m = cost.length; int[][] f = new int[m][n+1]; for(int i=1; i<=n; i++) { f[0][i] = Math.min(f[1][i-1], f[2][i-1]) + cost[0][i-1]; f[1][i] = Math.min(f[0][i-1], f[2][i-1]) + cost[1][i-1]; f[2][i] = Math.min(f[0][i-1], f[1][i-1]) + cost[2][i-1]; } int min = Math.min(Math.min(f[0][n], f[1][n]), f[2][n]); return min; } public static void main(String[] args) { int n = 6; int[][] cost = {{7,3,8,6,1,2},{5,6,7,2,4,3},{10,1,4,9,7,6}}; int min = minCost(n, cost); System.out.println(min); // 18 }
Reference:
http://www.careercup.com/question?id=9941005
相关推荐
LinkedIn-Ads-Guide-2020.pdf
Flagship-linkedin-release-campaign2.apk
中国B2B品牌全球化营销白皮书-Linkedin-8-86页.pdf
安装作曲家如果您使用的作曲家将其添加到您的依赖项中: "soroush/apply-with-linkedin-php": "dev-master" PHP OAUTH驱动程序您将需要安装PHP OAUTH驱动程序在计算机上执行此命令pecl install oauth 样本代码以PDF...
前端开源库-passport-linkedin-oauth2Passport-LinkedIn-OAuth2,LinkedIn OAuth2 API v2的Passport
graphql_linkedin:https://www.linkedin.comlearninggraphql-data-fetching-with-relay
聪明的浏览器插件为LinkedIn简化了生成和业务开发。 关于Dux-Soup:https://www.dux-soup.com Dux-Soup使您可以轻松地在LinkedIn上找到,吸引和吸引潜在客户。 它会自动查看潜在客户简介,认可技能,跟踪活动并代表...
领英python技能测试,搜集了30道原题,基本上15道里面能遇上一半原题。测试之前看一遍基本上稳过。奥利给!
cd linkedin-profile-info-api npm install 跑步 npm start 终点 GET /info/:username从给定的LinkedIn用户名以JSON格式返回配置文件信息 配置 应用程序使用的环境变量 PORT -公开API服务器的端口 PROXY_URL出站请求...
向LinkedIn添加其他工具,包括连接消息预设和各个用户注释。 此扩展程序可帮助您通过便笺系统记住与个人有关的信息,该信息系统已同步到您的Google帐户,并且仅对您可见。 它还允许拥有易于访问的连接消息预设,并...
Linkedin测验答案,技能评估测试 该资料库适合那些寻求LinkedIn评估测验问题答案或愿意通过参与测试来帮助他人的人。 或者,您可能想创建您的第一个拉取请求并被添加为贡献者。 无论您的目标是什么-在这里始终欢迎您...
类似于LinkedIn的软件的前端 具有基本功能的LinkedIn软件的克隆。 演示版 请在查看Netlify演示。 入门 这些说明将为您提供在本地计算机上运行并运行的项目的副本,以进行开发和... docker exec -it linkedin-react_l
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
LinkedIn 自动连接工具 ... 它会安装两个二进制文件: linkedin-auto-bot和lac到您的系统路径。 用法 使用lac命令按如下方式使用它: $ lab -u enter_your_linkedin_email > -k Enter LinkedIn password: ***
中国B2B品牌全球化营销白皮书-Linkedin-2019.8-86页.pdf
linkedin-trelloLinkedIn到Trello连接器,以遵循您的招聘流程的状态Accross您的组织链接到... linkedin-trelloLinkedIn到Trello连接器,以遵循您的招聘流程的状态Accross您的组织链接到维基。 ...
cd linkedin-export-tool npm install 配置 mkdir export cp config.json.dist config.json vim config.json 获取API密钥: 来自: 在哪里可以找到我的API密钥? 单击顶部导航菜单中的链接,以管理您的LinkedIn...