ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1651. Shortest Subchain

tle on 21
Posted by daizhenyang 16 Feb 2011 22:22
who can help me?
I use bfs.
Re: tle on 21
Posted by [NKU]sweet 3 Mar 2011 13:10
use dynamic programming
seq:1 2 7 3 2 8 4 8 5
dp :1 2 3 4 2 3 4 3 4
dp[i] -> dp[i+1]
or
dp[i] -> dp[j] while seq[i] == seq[j]
Notice that if much j exists, just goto the smallest j
the algorithm is O(N)

P.S : why netflow doesn't work now ? :)