Codeforces 164B || Codeforces 163A

Codeforces 164B

是个字符串问题(codeforces把这类问题归为two pointers),给了2个字符串a,b都可以任意移位,且b中无相等元素,满足条件“是a的子串==是b的子序列”的最大的串


 Codeforces 163A

(x,y)其中x==y,x为字符串a的子串,y为字符串b的子序列,问这样的序偶有多少个?

解:这是个DP的问题

The problem could be solved with the following dynamic programming. Let f[i, j] be the number of distinct pairs (“substring starting at position i” and “subsequence of the substring t[j… |t|]”)

Then:

f[i, j] = f[i, j + 1];
if (s[i] == t[j])
  add(f[i, j], f[i + 1, j + 1] + 1)

Answer = f[i,0]


 

 

 


 

 

posted on 2012-04-23 21:05  c语言源码  阅读(182)  评论(0编辑  收藏  举报

导航