Download presentation

Presentation is loading. Please wait.

Published byLanden Norton Modified over 2 years ago

1
HKOI 2005 Junior Q1 Pattern Matching ( 模式匹配 )

2
Question Given a target value (Sum of pattern P), find a sub-block with size equal to P having sum closest to the target value

3
Partial Solution Use 4 For-loop to calculate the sum of each sub-block. For “Top” from 1 to (M – N + 1) For “Left” from 1 to (M – N + 1) Calculate Sum of Sub-Block(Top, Left) If Sum < MinSum Update Complexity: O(M² N²)

4
Characteristic Two adjacent sub-block is overlap! Can we make use of this characteristic? Sum of Sub-Block(x, y) = Sum of Sub-Block(x – 1, y) - Sum of Column(1) of Sub-Block(x – 1, y) + Sum of Column(N) of Sub-Block(x, y) Improve a little bit only x-1, y x, y

5
Further Improvement Define a array SumFromTopLeft SumFromTopLeft(x, y) means the sum from Top-Left (1, 1) to (x, y) SumFromTopLeft(0, y) = 0 SumFromTopLeft(x, 0) = 0 SumFromTopLeft(x, y) = SumFromTopLeft(x, y - 1) + SumFromTopLeft(x - 1, y) - SumFromTopLeft(x - 1, y - 1) + PixelValue(x, y)

6
Con’t Sum of Sub-Block(x, y) x,y M – N + 1 = SumFromTopLeft(x + N - 1, y + N - 1) - SumFromTopLeft(x, y + N - 1) - SumFromTopLeft(x + N - 1, y) + SumFromTopLeft(x, y) Complexity: O(M²)

Similar presentations

OK

Addition. Early Level Language of Addition Children should be familiar with the various words used for addition: Total Find the sum of Plus Avoid the.

Addition. Early Level Language of Addition Children should be familiar with the various words used for addition: Total Find the sum of Plus Avoid the.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on indian textile industries inc Ppt on varactor diode characteristics Ppt on different occupations for kids Gastrointestinal tract anatomy and physiology ppt on cells Animated ppt on chemical bonding Ppt on project proposal writing Ppt on bluetooth security Ppt on index numbers in statistics Ppt on global warming and acid rain Types of window display ppt on ipad