본문으로 건너뛰기
cccskills
무료GitHub에 공개

dp-pattern-library

Maintain and match against a library of classic dynamic programming patterns. Provides pattern matching, template code generation, variant detection, and problem-to-pattern mapping for DP problems.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md8.9 KB
  • README.md8.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

dp-pattern-library

A specialized skill for dynamic programming pattern recognition, matching problems to known DP patterns, generating template code, and providing optimization guidance for DP solutions.

Purpose

Assist with dynamic programming by:

  • Matching problems to 50+ classic DP patterns
  • Generating template code for matched patterns
  • Detecting problem variants (knapsack variants, LCS variants, etc.)
  • Providing state design recommendations
  • Suggesting optimization techniques

Capabilities

Core Features

  1. Pattern Recognition

    • Analyze problem statement for DP indicators
    • Match to known pattern categories
    • Identify problem variants and transformations
    • Suggest state representation
  2. Pattern Categories

    • Linear DP (1D array)
    • Grid/Matrix DP (2D paths)
    • String DP (LCS, edit distance)
    • Interval DP (ranges, parenthesization)
    • Tree DP (subtree problems)
    • Bitmask DP (subset enumeration)
    • Digit DP (number counting)
    • Knapsack variants
    • DP with state machine
  3. Code Generation

    • Template code for recognized patterns
    • Multiple language support (Python, C++, Java)
    • Comments explaining state and transitions
    • Space-optimized variants
  4. Optimization Guidance

    • Rolling array technique
    • Convex hull trick
    • Divide and conquer optimization
    • Monotonic queue/stack optimization
    • Knuth optimization

Pattern Library

Linear DP Patterns

PatternStateTransitionExample Problems
Fibonaccidp[i] = answer for position idp[i] = dp[i-1] + dp[i-2]Climbing Stairs, House Robber
Min/Max Pathdp[i] = best answer ending at idp[i] = opt(dp[j]) + cost(j,i)Minimum Path Sum
Countingdp[i] = ways to reach state idp[i] = sum(dp[j])Unique Paths, Decode Ways
LISdp[i] = LIS ending at idp[i] = max(dp[j]) + 1 where j < i, a[j] < a[i]Longest Increasing Subsequence

String DP Patterns

PatternStateExample Problems
Edit Distancedp[i][j] = distance for s1[0..i], s2[0..j]Edit Distance, One Edit Distance
LCSdp[i][j] = LCS of s1[0..i], s2[0..j]Longest Common Subsequence
Palindromedp[i][j] = is s[i..j] palindromeLongest Palindromic Substring
Regex Matchdp[i][j] = s[0..i] matches p[0..j]Regular Expression Matching

Knapsack Patterns

VariantStateTransition
0/1 Knapsackdp[i][w] = max value with items 0..i, capacity wdp[i][w] = max(dp[i-1][w], dp[i-1][w-wt[i]] + val[i])
Unboundeddp[w] = max value with capacity wdp[w] = max(dp[w], dp[w-wt[i]] + val[i])
Boundeddp[i][w] = max value with limited itemsUse binary representation or deque
Subset Sumdp[i][s] = can reach sum s with items 0..idp[i][s] = dp[i-1][s] or dp[i-1][s-a[i]]

Grid DP Patterns

PatternStateExample Problems
Path Countdp[i][j] = ways to reach (i,j)Unique Paths, Unique Paths II
Path Min/Maxdp[i][j] = best path to (i,j)Minimum Path Sum
Multi-pathdp[i][j][k][l] = two paths simultaneouslyCherry Pickup

Interval DP Patterns

PatternStateExample Problems
MCMdp[i][j] = cost for range [i,j]Matrix Chain Multiplication
Burstdp[i][j] = max coins from balloons[i..j]Burst Balloons
Mergedp[i][j] = cost to merge range [i,j]Minimum Cost to Merge Stones

Tree DP Patterns

PatternStateExample Problems
Subtreedp[v] = answer for subtree rooted at vBinary Tree Maximum Path Sum
Rerootingdp[v] = answer when v is rootSum of Distances in Tree
Parent-Childdp[v][0/1] = answer with constraintHouse Robber III

Bitmask DP Patterns

PatternStateExample Problems
TSPdp[mask][last] = min cost visiting mask cities ending at lastTraveling Salesman Problem
Assignmentdp[mask] = min cost assigning tasks to subsetTask Assignment
SOSdp[mask] = sum over subsetsSubset Sum over Subsets

Usage

Pattern Matching

# Match problem to DP pattern
dp-pattern-library match --problem "Given an array of integers, find the longest increasing subsequence"

# Output:
# Pattern: Linear DP - Longest Increasing Subsequence (LIS)
# State: dp[i] = length of LIS ending at index i
# Transition: dp[i] = max(dp[j] + 1) for all j < i where arr[j] < arr[i]
# Time: O(n^2) naive, O(n log n) with binary search
# Space: O(n)

Template Generation

# Generate template code
dp-pattern-library template --pattern "lis" --language python

# Output:
def lengthOfLIS(nums):
    if not nums:
        return 0

    n = len(nums)
    # dp[i] = length of LIS ending at index i
    dp = [1] * n

    for i in range(1, n):
        for j in range(i):
            if nums[j] < nums[i]:
                dp[i] = max(dp[i], dp[j] + 1)

    return max(dp)

Optimization Suggestions

# Get optimization recommendations
dp-pattern-library optimize --pattern "lis"

# Output:
# Current: O(n^2) time, O(n) space
# Optimizations:
# 1. Binary Search: O(n log n) time
#    - Maintain sorted list of smallest tail elements
#    - Binary search for insertion point
# 2. Segment Tree: O(n log n) time
#    - For coordinate compression + range max query

Output Schema

{
  "match": {
    "pattern": "Linear DP - LIS",
    "confidence": 0.95,
    "category": "linear",
    "variants": ["LIS", "LDS", "LNDS"]
  },
  "state": {
    "description": "dp[i] = length of LIS ending at index i",
    "dimensions": 1,
    "meaning": "LIS length ending at position i"
  },
  "transition": {
    "formula": "dp[i] = max(dp[j] + 1) for j < i, arr[j] < arr[i]",
    "baseCase": "dp[i] = 1 for all i",
    "order": "left to right"
  },
  "complexity": {
    "time": "O(n^2)",
    "space": "O(n)",
    "optimized": {
      "time": "O(n log n)",
      "technique": "binary search on patience sort"
    }
  },
  "template": {
    "python": "...",
    "cpp": "...",
    "java": "..."
  },
  "similarProblems": [
    "Longest Increasing Subsequence",
    "Number of Longest Increasing Subsequence",
    "Russian Doll Envelopes",
    "Maximum Length of Pair Chain"
  ]
}

Integration with Processes

This skill enhances:

  • dp-pattern-matching - Core pattern matching workflow
  • dp-state-optimization - State space optimization
  • dp-transition-derivation - Deriving transitions
  • leetcode-problem-solving - DP problem identification
  • classic-dp-library - Building a personal DP library

Pattern Recognition Indicators

IndicatorLikely Pattern
"maximum/minimum" + "subarray/subsequence"Linear DP
"number of ways"Counting DP
"can reach/achieve"Boolean DP
"edit/transform string"String DP
"merge/combine intervals"Interval DP
"tree/subtree"Tree DP
"select subset" + small nBitmask DP
"count numbers with property"Digit DP
"items + capacity"Knapsack

References

Error Handling

ErrorCauseResolution
NO_PATTERN_MATCHProblem doesn't fit known patternsConsider greedy or other approaches
AMBIGUOUS_MATCHMultiple patterns could applyProvide more problem details
COMPLEX_STATEState too complex for templatesManual state design needed

Best Practices

  1. Start with brute force - Understand recurrence before optimizing
  2. Draw state diagram - Visualize transitions
  3. Verify base cases - Most DP bugs are in base cases
  4. Check state uniqueness - Each state should be uniquely defined
  5. Consider space optimization - Often can reduce dimension
  6. Test with small inputs - Trace through by hand

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Provide implementations of advanced data structures

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Fresh adversarial code review with binary PASS/FAIL verdicts, evidence citations, and anchoring bias prevention via fresh reviewer spawning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

WASM-based instant code transforms for simple tasks, achieving 352x speedup over LLM inference with zero cost.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Coordinate Crew (persistent) and Polecat (transient) agents using Gas Town's hook-based work distribution and GUPP principle.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Generate visual representations of algorithm execution

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Hierarchical coordination and drift detection with frequent checkpoints, shared memory coherence validation, role specialization enforcement, and short task cycles.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

a5c-ai의 스킬 모두 보기

이 스킬의 문제 신고