動的計画法

LeetCode

【LeetCode】509. Fibonacci Number 解答・解説【Python】

はじめに LeetCodeの問題を解答します。 なるべく、問題の和訳と詳細なコメントを書いています。 余裕があれば、複数のアプローチの解答と、実際の面接を想定して英語での解法やコメントを書いています。 ...
LeetCode

【LeetCode】300. Longest Increasing Subsequence 解答・解説【Python】

問題 原文 Given an integer array nums, return the length of the longest strictly increasing  subsequence . ...
Python

【LeetCode】413. Arithmetic Slices 解答・解説【Python】

問題 原文 An integer array is called arithmetic if it consists of at least three elements and if the difference between ...
Python

【LeetCode】62. Unique Paths 解答・解説【Python】

問題 原文 There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid). The rob...
LeetCode

【LeetCode】5. Longest Palindromic Substring 解答・解説【Python】

問題 原文 Given a string s, return the longest palindromic substring in s. Example 1: Example 2: Constraint...
LeetCode

【LeetCode】118. Pascal’s Triangle 解答・解説【Python】

はじめに LeetCodeの問題を解答します。 なるべく、問題の和訳と詳細なコメントを書いています。 余裕があれば、複数のアプローチの解答と、実際の面接を想定して英語での解法やコメントを書いています。 ...
Atcoder

【Educational DP Contest】EDPC-B-Frog2【Python】

問題 B - Frog 2 (atcoder.jp) 解答 方針 dp:i番目の足場でのコストの最小値 遷移式:dp = min(dp,dp+abs(H-H)) 解答 コード・コメント コード その他 解答・...
Atcoder

【Educational DP Contest】EDPC-A-Frog1【Python】

問題 A - Frog 1 (atcoder.jp) 解答 方針 ・ dpをi番目の足場でのコストの最小値とする ・遷移式:dp = min(dp+abs(h-h),dp+abs(h-h)) 解答 コード・コメント ...
Atcoder

【ABC129】AtCoder Beginner Contest 129 A,C問題 解答【Python】

A問題 Airplane C問題 方針 ・dp:n段目までの階段の登り方の数とする ・dpを求めるための遷移式:dp=dp+dp ・壊れている階段を配列で管理し、壊れていない場合のみ登り方の数を計算する ・壊れて...
Atcoder

【Python】AtCoder Beginner Contest 011 A,C問題 解答

A問題 来月は何月? 今が何月かという情報から来月を出力する問題です。 今が12月かそれ以外かで条件分岐をさせてみました。 今が12月である場合は1を出力。今が12月以外の場合は1を加えて出力しています。 今回は問題...