poscat seminar 8
Post on 15-Apr-2017
121 Views
Preview:
TRANSCRIPT
POSCAT Seminar 8 :Dynamic Programming 2
yougatup @ POSCAT
1
Topic
Topic today
− Dynamic Programming
• Longest Palindrome
• Team Division
POSCAT Seminar 1-29 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
POSCAT Seminar 1-39 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
POSCAT Seminar 1-49 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
1. Define the Table
POSCAT Seminar 1-59 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
1. Define the Table
let 𝑇 𝑖, 𝑗 = the length of longest palindrome on 𝑎𝑖 ~ 𝑎𝑗
POSCAT Seminar 1-69 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
2. Find a recurrence relation
POSCAT Seminar 1-79 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
2. Find a recurrence relation
Consider the case when 𝑎𝑖 = 𝑎𝑗 or not
POSCAT Seminar 1-89 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
2. Find a recurrence relation
𝑇 𝑖, 𝑗 = 𝑇 𝑖 + 1, 𝑗 − 1 + 2 𝑖𝑓 𝑎𝑖 = 𝑎𝑗
max 𝑇 𝑖 + 1, 𝑗 , 𝑇 𝑖, 𝑗 − 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
POSCAT Seminar 1-99 July 2014
yougatup
Longest Palindrome
Problem
A palindrome is a word that reads the same forward or reversed
Given string, find the length of longest palindrome among the
subsequence.
b a b a c v a b b a
3. Calculate !
Think carefully about the filling direction
POSCAT Seminar 1-109 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 5 3 4 2 6 7 3 4
POSCAT Seminar 1-119 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 / 5 3 4 2 6 / 7 3 4
POSCAT Seminar 1-129 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 / 5 3 4 2 6 / 7 3 4
3 20 14
POSCAT Seminar 1-139 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 / 5 3 4 2 6 / 7 3 4
3 20 14
∴ we get 20
POSCAT Seminar 1-149 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 5 3 / 4 2 6 / 7 3 4
POSCAT Seminar 1-159 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 5 3 / 4 2 6 / 7 3 4
11 12 14
POSCAT Seminar 1-169 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
For example, let 𝑚 = 3
1 2 5 3 / 4 2 6 / 7 3 4
11 12 14
∴ we get 14 much better !
POSCAT Seminar 1-179 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
1. Define the Table
POSCAT Seminar 1-189 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
1. Define the Table
𝑇 𝑖, 𝑗 = the minimum value when we divide 𝑎1 ~ 𝑎𝑗 into 𝑖
chunks
POSCAT Seminar 1-199 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
2. Find a recurrence relation
POSCAT Seminar 1-209 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
2. Find a recurrence relation
𝑇 𝑖, 𝑗 = min(max( 𝑇 𝑖 − 1, 𝑘 , 𝐶𝑜𝑠𝑡 𝑘 + 1, 𝑗 ) )
𝑓𝑜𝑟 𝑎𝑙𝑙 𝑖 ≤ 𝑘 ≤ 𝑗
After making i-1 chunks from 𝑎1 ~ 𝑎𝑘,make ONE chunk as
𝑎𝑘+1 ~ 𝑎𝑗 for all possible k.
POSCAT Seminar 1-219 July 2014
yougatup
Team Division
Problem
Suppose that we can divide 𝑛 numbers into 𝑚 chunks.
Minimize the maximum value of sum of each chunk.
3. Calculate !
POSCAT Seminar 1-229 July 2014
yougatup
top related