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.
What this skill does
# 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
| Pattern | State | Transition | Example Problems |
|---------|-------|------------|------------------|
| **Fibonacci** | dp[i] = answer for position i | dp[i] = dp[i-1] + dp[i-2] | Climbing Stairs, House Robber |
| **Min/Max Path** | dp[i] = best answer ending at i | dp[i] = opt(dp[j]) + cost(j,i) | Minimum Path Sum |
| **Counting** | dp[i] = ways to reach state i | dp[i] = sum(dp[j]) | Unique Paths, Decode Ways |
| **LIS** | dp[i] = LIS ending at i | dp[i] = max(dp[j]) + 1 where j < i, a[j] < a[i] | Longest Increasing Subsequence |
### String DP Patterns
| Pattern | State | Example Problems |
|---------|-------|------------------|
| **Edit Distance** | dp[i][j] = distance for s1[0..i], s2[0..j] | Edit Distance, One Edit Distance |
| **LCS** | dp[i][j] = LCS of s1[0..i], s2[0..j] | Longest Common Subsequence |
| **Palindrome** | dp[i][j] = is s[i..j] palindrome | Longest Palindromic Substring |
| **Regex Match** | dp[i][j] = s[0..i] matches p[0..j] | Regular Expression Matching |
### Knapsack Patterns
| Variant | State | Transition |
|---------|-------|------------|
| **0/1 Knapsack** | dp[i][w] = max value with items 0..i, capacity w | dp[i][w] = max(dp[i-1][w], dp[i-1][w-wt[i]] + val[i]) |
| **Unbounded** | dp[w] = max value with capacity w | dp[w] = max(dp[w], dp[w-wt[i]] + val[i]) |
| **Bounded** | dp[i][w] = max value with limited items | Use binary representation or deque |
| **Subset Sum** | dp[i][s] = can reach sum s with items 0..i | dp[i][s] = dp[i-1][s] or dp[i-1][s-a[i]] |
### Grid DP Patterns
| Pattern | State | Example Problems |
|---------|-------|------------------|
| **Path Count** | dp[i][j] = ways to reach (i,j) | Unique Paths, Unique Paths II |
| **Path Min/Max** | dp[i][j] = best path to (i,j) | Minimum Path Sum |
| **Multi-path** | dp[i][j][k][l] = two paths simultaneously | Cherry Pickup |
### Interval DP Patterns
| Pattern | State | Example Problems |
|---------|-------|------------------|
| **MCM** | dp[i][j] = cost for range [i,j] | Matrix Chain Multiplication |
| **Burst** | dp[i][j] = max coins from balloons[i..j] | Burst Balloons |
| **Merge** | dp[i][j] = cost to merge range [i,j] | Minimum Cost to Merge Stones |
### Tree DP Patterns
| Pattern | State | Example Problems |
|---------|-------|------------------|
| **Subtree** | dp[v] = answer for subtree rooted at v | Binary Tree Maximum Path Sum |
| **Rerooting** | dp[v] = answer when v is root | Sum of Distances in Tree |
| **Parent-Child** | dp[v][0/1] = answer with constraint | House Robber III |
### Bitmask DP Patterns
| Pattern | State | Example Problems |
|---------|-------|------------------|
| **TSP** | dp[mask][last] = min cost visiting mask cities ending at last | Traveling Salesman Problem |
| **Assignment** | dp[mask] = min cost assigning tasks to subset | Task Assignment |
| **SOS** | dp[mask] = sum over subsets | Subset Sum over Subsets |
## Usage
### Pattern Matching
```bash
# 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
```bash
# 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
```bash
# 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
```json
{
"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
| Indicator | Likely 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 n | Bitmask DP |
| "count numbers with property" | Digit DP |
| "items + capacity" | Knapsack |
## References
- [Dynamic Programming Patterns](https://github.com/aatalyk/Dynamic-Programming-Patterns)
- [DP Visualization Tools](https://dp.debkbanerji.com/)
- [LeetCode DP Patterns](https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns)
- [CP Algorithms - DP](https://cp-algorithms.com/dynamic_programming.html)
- [CSES DP Section](https://cses.fi/problemset/list/)
## Error Handling
| Error | Cause | Resolution |
|-------|-------|------------|
| `NO_PATTERN_MATCH` | Problem doesn't fit known patterns | Consider greedy or other approaches |
| `AMBIGUOUS_MATCH` | Multiple patterns could apply | Provide more problemRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.