📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
查看: 2647| 回复: 6
跳转到指定楼层
上一主题 下一主题
收起左侧

google : 记电话号码

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
//You are given a String number containing the digits of a
//phone number (the number of digits, n, can be any positive integer) . To help you memorize
//the number, you want to divide it into groups of contiguous digits. Each group must contain
//exactly 2 or 3 digits. There are three kinds of groups:
//• Excellent: A group that contains only the same digits. For example, 000 or 77.
//• Good: A group of 3 digits, 2 of which are the same. For example, 030, 229 or 166.
//• Usual: A group in which all the digits are distinct. For example, 123 or 90.
//The quality of a group assignment is defined as
//2 × (number of excellent groups) + (number of good groups)
//Divide the number into groups such that the quality is maximized. Design an efficient
//algorithm to return the solution that maximizes the quality.

上一篇:Microsoft : 二叉树子结构
下一篇:Bloomberg : 输出排列个数
🔗
Etrnls 2011-5-11 14:36:23 | 只看该作者
全局:
f(i) = max(
f(i - 2) + 2 ---> if number(i - 1) == number(i),
f(i - 3) + 2 ---> if number(i - 2) == number(i - 1) == number(i),
f(i - 3) + 1 ---> if number(i - 2, i - 1, i) is Good,
f(i - 1)
)
回复

使用道具 举报

🔗
darksteel 2011-5-11 14:38:35 | 只看该作者
全局:
回复 2# Etrnls
嗯,好像是非常典型的DP问题,不过还需要加上f(i-1)吗?每个group不是必须是2或3个digits吗
回复

使用道具 举报

🔗
Etrnls 2011-5-11 16:25:35 | 只看该作者
全局:
回复 3# darksteel

囧……写错了@@
最后那个f(i - 1)应该是f(i - 2)...
回复

使用道具 举报

🔗
Etrnls 2011-5-11 19:38:18 | 只看该作者
全局:
唉……最近越来越2了……
最后那个f(i - 1)应该是两项,f(i - 2), f(i - 3)
回复

使用道具 举报

🔗
darksteel 2011-5-11 23:24:58 | 只看该作者
全局:
回复 5# Etrnls
没有路线错误就好,真正写的时候肯定会注意到的
回复

使用道具 举报

🔗
 楼主| wwwyhx 2011-5-12 12:43:56 | 只看该作者
全局:
恩,简单的DP问题
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表