SlideShare a Scribd company logo
1 of 10
gasin contest
問題
• 頂点数1000の有向完全グラフが与えられます(辺の情報は見る
ことができます)。頂点0から始めて全ての頂点を一度だけ通
り頂点0に戻ってくる経路のうち、できるだけ短いものを求め
よ。
• つまり、巡回セールスマン問題
• 以下のリンクにジャッジ用のコードとサンプルのコードがある
ので、始めたい人は始めてください
• https://github.com/gasin/procon1
巡回セールスマン問題とは
• NP困難と呼ばれるクラスに含まれる問題。
• 僕もよく理解していないが、とにかく効率的なアルゴリズムが
存在しない問題。
• 頂点数が1000などというサイズの問題が解けるわけがない
• 競プロなどにおいて巡回セールスマン問題が出るときの頂点数
はせいぜい12ぐらい。
巡回セールスマン問題(n<=12のとき)
• bitDPというテクニックを使うことで解くことができる。(詳
しくは蟻本を参照)
• 計算量はO(n*2^n)
• アイディアとしては、今いる頂点と、それまでに訪れた頂点の
情報が分かっていれば十分なので、経路を全て記憶している必
要がないということを利用してうまくDPをする。
では、どうするか
• このような問題はマラソンと呼ばれる長期間のコンテストで出
題されるような問題であり、最適解を求めることは諦めて、極
力よい解を求めるように頑張る。
• いきなり言われても難しいと思うので、いくつか有名な手法を
紹介します。(僕もマラソンは専門外なので詳しくないです
が)
貪欲(ヒューリスティック)
• よさそうな戦略を決めて、それを実装するだけ。シンプルだけ
ど戦略が強ければもちろん強いのでやってみる価値はあるしこ
れで勝てちゃうこともあるかもしれない。(ほとんどないけ
ど)
• 例えば、今回の巡回セールスマン問題においては今いる頂点か
ら生えている辺のうち最小コストの辺を選択するなどがこれに
あたる。(もちろん、条件を満たすように辺は選ぶ)
山登り法
• その場その場でより良いスコアへの改善を探索し、良いスコアを見
つけたらそれを採用するという操作を繰り返す。
• しかし、局所解に陥りやすいので工夫が必要になる。(しかし、そ
こそこのコンテストだとこれだけでなんとかなったりする)
• 今回の場合に適用すると、適当に経路を定め、その頂点を適当に
swapするなどして、もとの経路よりもコストが小さくなればそれを
採用するということを繰り返すなどの方法が考えられる。
• 上位互換として、焼きなまし法という方法があり、これは局所解に
陥りにくくしたもの。(温度という概念を導入し、現在の解よりも
悪くてもそれをある確率で採用するという操作を行う)
ビームサーチ
• マラソン系のコンテストにおいて、最も使われている手法(多
分)。派生系もたくさんある(chokudai searchなど)。
• 探索をするときに、全探索をするとメモリや時間が足りなくな
るので、そこを工夫しようというもので、よさそうな解をいく
つかだけ採用して他の場合を切り捨てるという考え方。
• いくつ採用するのか(ビームの幅)、よさそうとはなんなのか
(評価関数)など、考えることは多いので扱いが難しいといえ
ば難しい。
• 今回の問題で言えば、i頂点からなる経路のうち、短い経路を10
個だけ採用するなど。
頑張りましょう
• これらのテクニックはもちろん、複合することもできたりする
ので色々と工夫してみましょう。
• どの方法をとるにしても、試行回数は多ければ多い方が良いに
決まっているので、高速化や自動化は実装したほうが結果的に
はよいです。
• また、数字が大きいので基本的にlong long型を使ったほうがい
です。
• 経路の候補は1000!(2568桁らしい)もあり、最適解なんか求
まるわけもないので良い解が出ても、もっと良い解があるはず
だと思って改善を続けましょう。
最後に
• 一応、僕が出した最短経路のスコアは4763774です。
• 超えたぜという人は宣言してください。

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)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 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd 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 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 IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...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...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 Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How 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 InsightsSocial 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 2024Trends 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 summary5 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 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 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 IntentGoogle'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 How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe 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...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...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 Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT 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 RoutesMore 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
 

巡回セールスマン