Enviar búsqueda
Cargar
桁DP入門
•
0 recomendaciones
•
35 vistas
S
ShunsukeOtani1
Seguir
桁DPの入門スライドです
Leer menos
Leer más
Educación
Denunciar
Denunciar
1 de 28
Descargar ahora
Descargar para leer sin conexión
Recomendados
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
Recomendados
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
Introduction to C Programming Language
Introduction to C Programming Language
Simplilearn
Más contenido relacionado
Destacado
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
Introduction to C Programming Language
Introduction to C Programming Language
Simplilearn
Destacado
(20)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
ChatGPT webinar slides
ChatGPT webinar slides
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Introduction to C Programming Language
Introduction to C Programming Language
桁DP入門
1.
桁DP入門 Shunsuke Otani
2.
桁DPとは N以下の整数で○○の条件を満たす数の個数 N以下の整数で○○の条件を満たす数の最大値 などの問題で使える桁ごとに分けて考える動的計画法
3.
例題1 Q:100未満の整数で3がつく数の個数は? int型→string型で 数字に3がつくか 全探索? 10ごとに3がつく数は 1増えていそうだから N/10? O(N)では間に合わない ことも…
4.
桁DPの考え方(1の桁に3がつく) 10 1 0 3を含む 3を含まない 1の桁10の桁 全部 10×1 =
10 10の桁の数字 ※箱には○桁目まで見た時の答えが入ります
5.
桁DPの考え方(1の桁に3がつかない) 9 0 81 9 3を含む 3を含まない 1の桁10の桁 3以外 9
× (10 - 1) = 81 10の桁の数字 9 × 1 = 9 ※箱には○桁目まで見た時の答えが入ります
6.
桁DPの考え方(結果を足す) 19 1 81 9 3を含む 3を含まない 1の桁10の桁 100未満(~99)の範囲を求めるため、10の桁まで考えればよい ※箱には○桁目まで見た時の答えが入ります
7.
つまり 先ほどの遷移 + 条件
= 桁DP
8.
条件!???
9.
例題だと… N <
100 この条件を先ほどの遷移に加えたい…
10.
例題2 Q:55以下の整数で3がつく数の個数は?
11.
例題2(1の桁に3がつく) 53を含む 3を含まない 1の桁10の桁 0 1 0 N < 50
N >= 50 && N <= 55 1×5(0,1,2,3,4) 1 1の桁10の桁 0 1 0 1×1(5) 3を含む 3を含まない
12.
例題2(1の桁に3がつかない) 93を含む 3を含まない 1の桁10の桁 36 0 9 N < 50
N >= 50 && N <= 55 9×4(0,1,2,4) 0 1の桁10の桁 5 0 5 5×1(5) 3を含む 3を含まない 9×1(3)
13.
例題2(結果) 143を含む 3を含まない 1の桁10の桁 36 1 9 N < 50
N >= 50 && N <= 55 1 1の桁10の桁 5 1 5 3を含む 3を含まない よって答えは 14 + 1 = 15
14.
しかし… 2桁までの遷移は簡単にプログラムで実装できる Nが3桁以上になった場合は…?
15.
N <= 255のとき
下の桁から見る場合 1. (0~5),(0~9)それぞれの3の個数をカウント 2. (0~55),(0~99)1を使い、それぞれの3の個数をカウント 3. (0~255)2を使い、3の個数をカウント もう少し簡単なアルゴリズムはないのか… 上の桁から見てみよう!
16.
例題2(10の桁に3がつく) 13を含む 3を含まない 1の桁10の桁 0 10 0 N < 50
N >= 50 && N <= 55 1×10(0~9) 0 1の桁10の桁 0 0 0 0×6(0~5) 3を含む 3を含まない
17.
例題2(10の桁に3がつかない) 03を含む 3を含まない 1の桁10の桁 4 4 36 N < 50
N >= 50 && N <= 55 4×9(0~2,4~9) 0 1の桁10の桁 1 1 5 1×5(0,1,2,4,5) 3を含む 3を含まない 4×1(3) 1×1(3)
18.
例題2(結果) 13を含む 3を含まない 1の桁10の桁 4 14 36 N < 50
N >= 50 && N <= 55 0 1の桁10の桁 1 1 5 3を含む 3を含まない よって答えは 14 + 1 = 15
19.
上の桁から見てみよう 前頁と同条件(N<=255)で上の桁から見たとき 1.
(0~1),(2)の3の個数をカウント 2. (0~24),(25)1を使い、それぞれの3の個数をカウント 3. (0~254),(255)2を使い、それぞれの3の個数をカウント 見る順番を変えるだけで考えやすくなった! これをどうやって実装すれば…
20.
未満Flagを導入 Nの制約がない場合の遷移 dp[digit(N)][2] (dp[桁数][3の有無]) 未満Flagを導入
dp[digit(N)][2][2] (dp[桁数][3の有無][N未満]) dp[i][*][0]には N未満となる数についての答え dp[i][*][1]には i桁目までNと同じ数についての答え
21.
未満Flagの具体例 *先ほどのdpから3の有無を除いて考える N =
12345 dp[3][1]:123○○未満となる数(0~12299) つまり(0~122)の範囲の3がつく数の個数 dp[3][0]:123○○となる数(12300~12345) つまり(123)の3がつく数の個数
22.
遷移を見てみる *先ほどのdpから3の有無を除いて考える N = 12345
dp[3][0](123○○)→dp[4][*]の遷移は… dp[4][0]への遷移は(123○○)→(1234○)より dp[4][0]= dp[3][0] dp[4][1]への遷移は(123○○)→(123(0~3)○)より dp[4][1]= dp[3][0]×4(0~3の個数)
24.
簡単な問題から 1~Nの整数の個数を桁DPで求めてみよう まずはdpテーブルを考えてみよう!
25.
DPテーブルは… dp[digit(N)][smaller(未満Flag)]
26.
解法例
27.
演習タイム 1. 0からNまでの整数で3が含まれる数の個数を桁dpで求めてみよう! 2. 0からNまでの整数で桁の和が3の倍数な数の個数を桁dpで求めてみよう!
28.
ご清聴ありがとうございました
Descargar ahora