A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d7/d73/abbreviation_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/abbreviation.cpp Source File

60

std::vector<std::vector<bool>> *visited,

61 const

std::string &str,

const

std::string &result,

62

uint32_t str_idx = 0, uint32_t result_idx = 0) {

63 bool

ans = memo->at(str_idx).at(result_idx);

64 if

(str_idx == str.size() && result_idx == result.size()) {

66

}

else if

(str_idx == str.size() && result_idx != result.size()) {

69

}

else if

(!visited->at(str_idx).at(result_idx)) {

81 if

(str[str_idx] == result[result_idx]) {

83

str_idx + 1, result_idx + 1);

84

}

else if

(str[str_idx] - 32 == result[result_idx]) {

86

str_idx + 1, result_idx + 1) ||

88

str_idx + 1, result_idx);

94 if

(str[str_idx] >=

'A'

&& str[str_idx] <=

'Z'

) {

98

str_idx + 1, result_idx);

102

(*memo)[str_idx][result_idx] = ans;

103

(*visited)[str_idx][result_idx] =

true

;

104 return

(*memo)[str_idx][result_idx];

119bool abbreviation

(

const

std::string &str,

const

std::string &result) {

120

std::vector<std::vector<bool>> memo(

121

str.size() + 1, std::vector<bool>(result.size() + 1,

false

));

123 for

(uint32_t i = 0; i <= str.size(); ++i) {

126 for

(uint32_t i = 1; i <= result.size(); ++i) {

129 for

(uint32_t i = 1; i <= str.size(); ++i) {

130 for

(uint32_t j = 1; j <= result.size(); ++j) {

131 if

(str[i - 1] == result[j - 1]) {

132

memo[i][j] = memo[i - 1][j - 1];

133

}

else if

(str[i - 1] - 32 == result[j - 1]) {

134

memo[i][j] = (memo[i - 1][j - 1] || memo[i - 1][j]);

136 if

(str[i - 1] >=

'A'

&& str[i - 1] <=

'Z'

) {

139

memo[i][j] = memo[i - 1][j];

144 return

memo.back().back();

154

std::string s =

"daBcd"

, t =

"ABC"

;

155

std::vector<std::vector<bool>> memo(s.size() + 1,

156

std::vector<bool>(t.size() + 1,

false

)),

157

visited(s.size() + 1, std::vector<bool>(t.size() + 1,

false

));

160

&memo, &visited, s, t) ==

true

);

162

s =

"XXVVnDEFYgYeMXzWINQYHAQKKOZEYgSRCzLZAmUYGUGILjMDET"

;

163

t =

"XXVVDEFYYMXWINQYHAQKKOZEYSRCLZAUYGUGILMDETQVWU"

;

164

memo = std::vector<std::vector<bool>>(

165

s.size() + 1, std::vector<bool>(t.size() + 1,

false

));

167

visited = std::vector<std::vector<bool>>(

168

s.size() + 1, std::vector<bool>(t.size() + 1,

false

));

171

&memo, &visited, s, t) ==

false

);

174

s =

"DRFNLZZVHLPZWIupjwdmqafmgkg"

;

175

t =

"DRFNLZZVHLPZWI"

;

177

memo = std::vector<std::vector<bool>>(

178

s.size() + 1, std::vector<bool>(t.size() + 1,

false

));

180

visited = std::vector<std::vector<bool>>(

181

s.size() + 1, std::vector<bool>(t.size() + 1,

false

));

184

&memo, &visited, s, t) ==

true

);

bool abbreviation_recursion(std::vector< std::vector< bool > > *memo, std::vector< std::vector< bool > > *visited, const std::string &str, const std::string &result, uint32_t str_idx=0, uint32_t result_idx=0)

Recursive Dynamic Programming function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4