avatar
f*r
1
一个字符数组a[1]...a[n]. 给一个字符集合{c1,...ck}, 找出包含c1,...ck的最短的
这个题目是dp?
有知道的大侠给个思路,非常感谢!
avatar
J*n
2
一哥们儿隔壁新搬来个老外,一天晚上老外敲门求助,说:“我的电视坏了,不能换台
。”这哥们儿低头看了眼表,很镇定的说: “全国的电视在晚上七点到七点
半都会发作这种病毒的。
avatar
r*o
3
这个是不是返回包含c1...ck的最大范围?
avatar
m*i
4
北韩?

【在 J*****n 的大作中提到】
: 一哥们儿隔壁新搬来个老外,一天晚上老外敲门求助,说:“我的电视坏了,不能换台
: 。”这哥们儿低头看了眼表,很镇定的说: “全国的电视在晚上七点到七点
: 半都会发作这种病毒的。

avatar
y*c
5
DP is one approach. But it should take O(n^2)
opt(j) = maximum number of chars in C from a[0] to [j]
start(j) = largest i, st. a[i] to a[j] contains opt(j) chars in C
Then try to compute opt(j) from opt(j-1) and start(j-1).
You only need to start from start(j-1). If opt(j) is a new char, opt(j)=opt(
j-1)+1 (a hash or map needs to be maintained to store all chars in C that
have been seen), otherwise, update start(j) (e.g. if a[start(j-1)] = a[j],
etc.) This would take up to j. So at the end it ta
avatar
s*s
6
avatar
s*t
7
汗,看走眼了

【在 r****o 的大作中提到】
: 这个是不是返回包含c1...ck的最大范围?
avatar
k*e
8
true. 《新闻联播》时间。

【在 s***s 的大作中提到】
: 假
avatar
s*l
9
我也觉得是~~

【在 r****o 的大作中提到】
: 这个是不是返回包含c1...ck的最大范围?
avatar
c*o
10
像是天朝,但是天朝现在不是每个台都转新闻联播的了。

【在 m****i 的大作中提到】
: 北韩?
avatar
g*u
11
这个复杂度我觉得不能做到O(n),因为还要看k
我觉得是O(nlogk)

【在 f*******r 的大作中提到】
: 一个字符数组a[1]...a[n]. 给一个字符集合{c1,...ck}, 找出包含c1,...ck的最短的
: 这个题目是dp?
: 有知道的大侠给个思路,非常感谢!

avatar
d*n
12
Use hashtable, we can achieve O(n)

【在 g*****u 的大作中提到】
: 这个复杂度我觉得不能做到O(n),因为还要看k
: 我觉得是O(nlogk)

avatar
f*r
13
能解释的详细点吗?谢谢了:)

【在 d****n 的大作中提到】
: Use hashtable, we can achieve O(n)
avatar
l*a
14
这个题昨天就讨论过
http://www.mitbbs.com/article_t/JobHunting/31586251.html

【在 f*******r 的大作中提到】
: 一个字符数组a[1]...a[n]. 给一个字符集合{c1,...ck}, 找出包含c1,...ck的最短的
: 这个题目是dp?
: 有知道的大侠给个思路,非常感谢!

avatar
d*n
15
Here is the code in C#, please do let me know if you find any bug
// This program returns the shortest substring is src
// which contains all charactors in dest
// INT_MAX returned if no coverage found
static int MinimumCover(string src, string dst)
{
int minDist = int.MaxValue;
Hashtable ht = new Hashtable();
ArrayList al = new ArrayList();
foreach (char c in dst)
{
ht.Add(c,1);


【在 f*******r 的大作中提到】
: 能解释的详细点吗?谢谢了:)
avatar
d*n
16
Forgot one small class:
class charPos {
public charPos(int pos, char ch)
{
m_ch=ch;
m_pos=pos;
}
public char m_ch;
public int m_pos;
};

【在 d****n 的大作中提到】
: Here is the code in C#, please do let me know if you find any bug
: // This program returns the shortest substring is src
: // which contains all charactors in dest
: // INT_MAX returned if no coverage found
: static int MinimumCover(string src, string dst)
: {
: int minDist = int.MaxValue;
: Hashtable ht = new Hashtable();
: ArrayList al = new ArrayList();
: foreach (char c in dst)

avatar
r*o
17
能不能讲讲思路啊,这个复杂度好像不是O(n),for里面还有while.

【在 d****n 的大作中提到】
: Here is the code in C#, please do let me know if you find any bug
: // This program returns the shortest substring is src
: // which contains all charactors in dest
: // INT_MAX returned if no coverage found
: static int MinimumCover(string src, string dst)
: {
: int minDist = int.MaxValue;
: Hashtable ht = new Hashtable();
: ArrayList al = new ArrayList();
: foreach (char c in dst)

avatar
l*a
18
while是针对保存match状态的hashtabl而言。
对于原字符串,就是一个O(n)的扫描

【在 r****o 的大作中提到】
: 能不能讲讲思路啊,这个复杂度好像不是O(n),for里面还有while.
avatar
s*t
19
a = "what the hell is this"
k = ('e','h','s')
def longestSubString(a, k):
n=len(a)
dp = {}
dp[(0,0)] = {}
for j in k:
if a[0]==j:
dp[(0,0)][j] = 1
else:
dp[(0,0)][j] = 0
x=0;y=0;minlength = n+1;
while y## print dp[(x,y)], a[x:y+1]
if not (0 in dp[(x,y)].values()):
"""found substr"""
if y-x+1 < minlength:
"""update minlength if necessary"""
minlength =

【在 f*******r 的大作中提到】
: 一个字符数组a[1]...a[n]. 给一个字符集合{c1,...ck}, 找出包含c1,...ck的最短的
: 这个题目是dp?
: 有知道的大侠给个思路,非常感谢!

avatar
s*t
20
思路见注释

【在 s*********t 的大作中提到】
: a = "what the hell is this"
: k = ('e','h','s')
: def longestSubString(a, k):
: n=len(a)
: dp = {}
: dp[(0,0)] = {}
: for j in k:
: if a[0]==j:
: dp[(0,0)][j] = 1
: else:

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。