Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

How to find all the ways to construct a string using dynamic programming memoization?

Правка en4, от SHUVRO.C.DAS, 2021-01-11 14:02:40

The problem statement is, You are given a string and an array of some words. All the words are substring of the given string. You have to find all the ways to construct the string from the words of the array.

Suppose you are given a string "abcdef" and an array={ab,abc,cd,def,abcd}; here only one way to construct the string is ="abc+def"

my code prints all the ways. But it is really inefficient. it prints the same path multiple times if exists. It visits all the nodes. I want suggestions to memoize it so that it doesn't visit the same path if it visited it before. Can someone help me?

here is my code: https://github.com/Shuvro-d/Dynamic.Programming/blob/main/test.cpp

Теги #c++, #string, #dynamic programing, #memoization

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский SHUVRO.C.DAS 2021-01-11 14:03:15 0 (published)
en4 Английский SHUVRO.C.DAS 2021-01-11 14:02:40 20 (saved to drafts)
en3 Английский SHUVRO.C.DAS 2021-01-11 13:57:51 65
en2 Английский SHUVRO.C.DAS 2021-01-11 13:54:04 668
en1 Английский SHUVRO.C.DAS 2021-01-11 13:53:22 1354 Initial revision (published)