惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
B
Blog
WordPress大学
WordPress大学
Project Zero
Project Zero
P
Palo Alto Networks Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
T
Tailwind CSS Blog
Forbes - Security
Forbes - Security
F
Full Disclosure
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News: Ask HN
Hacker News: Ask HN
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
G
Google Developers Blog
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
O
OpenAI News
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
IT之家
IT之家
U
Unit 42
腾讯CDC
S
Security Affairs
C
Cisco Blogs
Schneier on Security
Schneier on Security
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss

博客园 - 比尔盖房

USACO: Section 1.5 -- PROB Prime Palindromes USACO: Section 1.4 -- PROB Arithmetic Progressions USACO: Section 1.3 -- PROB Prime Cryptarithm USACO: Section 1.3 -- PROB Barn Repair USACO: Section 1.3 -- PROB Mixing Milk USACO: Section 1.2 -- PROB Dual Palindromes USACO: Section 1.2 -- PROB Palindromic Squares Programming Pearls: Chatper3 Problem6 [Form letter generator] Programming Pearls: Chatper3 Problem5 [Hyphenation Words] Programming Pearls: Chatper3 Problem4 [Dates Caculation] Programming Pearls: Chatper3 Problem3 [Print Banner] Studying Probability Theory Studying "Concrete Mathematics" Studying "Introduction to Algorithms" Testing SEH tips How DebuggerRCThread is lauched? Public Symbols vs Private Symbols[zt] The magic of NativeWindow-- How does .Net Winform manage Win32 controls .Net Windows Service
USACO: Section 1.5 -- PROB Number Triangles
比尔盖房 · 2008-07-06 · via 博客园 - 比尔盖房

Source Code

This problem requires us to search all the possible paths. For every level i, the i+1 level has searching choices: f(i+1)=2*f(i). So, for R rows, the final level paths are O(2^R). This calculation paths number is not acceptable for computer since R can be 1000. We need some way to reduce the paths.

Then, we see the insight. We find that for level i, there should be i paths for decisions. For item (i, j), we can filter other paths to it and just keep one current max sum path. This is just the dynamic programming. We have paths 1+2+3...+R = O(R^2) paths, which is acceptable for calculation now.

Lesson Learned:
1. The difference between dynamic programming and brute-force searching is that there may be some redundant states during the searching. That is, the searching tree has many nodes that are the same node coming from other parent nodes. So, the tree nodes numbers are not that large if we filter the redundant nodes. So, we can dynamically judge in the middle state to filter a lot of search paths. This will greatly improve the searching boundaries.
2. Set code copying operation as an alarm.
3. While looping through a 2-d array, we'd better use indexing varialbe names "row", "item" instead of "i", "j" for readability reason.
4. Always assert the index range before using the index to access array items.