Test a code.
\nrust []\nimpl Solution {\n    pub fn min_valid_strings(words: Vec<String>, target: String) -> i32 {\n        let mut ps = vec![0; target.len() + 1];\n        
\n```rust []\nimpl Solution {\n    pub fn min_valid_strings(words: Vec<String>, target: String) -> i32 {\n        let mut ps = vec![0; target.len() + 1];\n        for w in words.iter() {\n            let pi = Self::prefix_function(&format!("{}#{}", w, target));\n            for i in 1..=target.len() {\n                ps[i] = ps[i].max(pi[w.len() + i]);\n            }\n        }\n        let mut len = target.len() as i32;\n        let mut res = 0;\n        while len > 0 && ps[len as usize] > 0 {\n            res += 1;\n            len -= ps[len as usize];\n        }\n        if len == 0 {\n            res\n        } else {\n            -1\n        }\n    }\n\n    fn prefix_function(s: &str) -> Vec<i32> {\n        let s = s.as_bytes();\n        let n = s.len();\n        let mut pi = vec![0_i32; n];\n        let mut i = 1;\n        while i < n {\n            let mut j = pi[i - 1];\n            while j > 0 && s[i] != s[j as usize] {\n                j = pi[(j - 1) as usize];\n            }\n            if s[i] == s[j as usize] {\n                j += 1;\n            }\n            pi[i] = j;\n            i += 1;\n        }\n        pi\n    }\n}\n\n```
['Rust']