forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
76 lines (63 loc) · 1.39 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool solved;
vector<string> sol;
string s;
int L;
bool check(){
int k = sol.size();
for(int i = 0;i < k;++i){
for(int j = i + 1;j < k;++j){
if(sol[i] == sol[j]) return false;
}
}
return true;
}
void solve(int k, int pos){
if(pos == L) return;
if(k == 0){
sol.push_back(s.substr(pos,L - pos));
if(check()){
solved = true;
return;
}
sol.pop_back();
}
for(int i = pos;i < L;++i){
sol.push_back(s.substr(pos,i - pos + 1));
solve(k - 1,i + 1);
if(solved) return;
sol.pop_back();
}
}
int main(){
int t,k;
cin >> t;
while(t--){
cin >> s >> k;
L = s.size();
if(L >= k * (k + 1) / 2){
cout << "YES\n";
for(int i = 0,p = 0;i < k;++i){
int len = i + 1;
if(i == k - 1) len = L - p;
cout << s.substr(p,len) << "\n";
p += len;
}
}else{
sol.clear();
solved = false;
solve(k - 1,0);
if(!solved) cout << "NO\n";
else{
cout << "YES\n";
for(string s : sol){
cout << s << "\n";
}
}
}
}
return 0;
}