-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5265530
commit ee60eeb
Showing
6 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("fewestFlops_UVA11552.in"); | ||
ofstream fout("fewestFlops_UVA11552.out"); | ||
|
||
const int inf = INT_MAX / 3; | ||
|
||
int ctoi(char ch) | ||
{ | ||
return ch - 'a'; | ||
} | ||
|
||
int main() | ||
{ | ||
int ac = 26; | ||
string alphabets = "abcdefghijklmnopqrstuvwxyz"; | ||
|
||
int tcc; fin >> tcc; | ||
for (int t = 1; t <= tcc; ++t) | ||
{ | ||
int k; fin >> k; | ||
string s; fin >> s; | ||
|
||
int n = s.size(), lastMin = inf, nowMin = inf; | ||
vector<vector<int>> dp(n / k, vector<int>(ac, inf)); | ||
for (int i = 0; i <= n - 1; i += k) | ||
{ | ||
string now = s.substr(i, k), allChar = ""; | ||
vector<int> count(ac + 1, 0); | ||
|
||
for (int j = 0; j <= k - 1; ++j) | ||
{ | ||
if (count[ctoi(now[j])] == 0) | ||
{ | ||
allChar += now[j]; | ||
} | ||
++count[ctoi(now[j])]; | ||
} | ||
|
||
int tc = allChar.size(); | ||
if (i == 0) | ||
{ | ||
for (int j = 0; j <= tc - 1; ++j) | ||
{ | ||
dp[i / k][ctoi(allChar[j])] = tc; | ||
} | ||
lastMin = tc; | ||
} | ||
else | ||
{ | ||
for (int p = 0; p <= tc - 1; ++p) | ||
{ | ||
for (int q = 0; q <= tc - 1; ++q) | ||
{ | ||
if (p == q && tc > 1) continue; | ||
|
||
char head = allChar[p], tail = allChar[q]; | ||
|
||
if (dp[i / k][ctoi(tail)] == inf) dp[i / k][ctoi(tail)] = lastMin + tc; | ||
|
||
dp[i / k][ctoi(tail)] = min(dp[i / k][ctoi(tail)], dp[i / k - 1][ctoi(head)] + tc - 1); | ||
|
||
nowMin = min(nowMin, dp[i / k][ctoi(tail)]); | ||
} | ||
} | ||
|
||
lastMin = nowMin; | ||
nowMin = inf; | ||
} | ||
} | ||
|
||
fout << lastMin << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
12 | ||
6 nuxxzrzbmnmgqooket | ||
6 nuxxzrzbmnmgqooketlyhnko | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqr | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiut | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwa | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvs | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsaj | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgub | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgubfaaovl | ||
6 nuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgubfaaovlzylntr | ||
6 augzqr | ||
6 augzqrcddiut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
14 | ||
19 | ||
25 | ||
29 | ||
34 | ||
39 | ||
44 | ||
50 | ||
54 | ||
59 | ||
6 | ||
10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ofstream fout("fewestFlops_UVA11552.in"); | ||
|
||
int getRand(int a, int b) | ||
{ | ||
int c = b - a + 1; | ||
return rand() % c + a; | ||
} | ||
|
||
int main() | ||
{ | ||
//string alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
string alphabets = "abcdefghijklmnopqrstuvwxyz"; | ||
int ac = alphabets.size(); | ||
|
||
int tcc = 1000, maxN = 10; | ||
fout << tcc << '\n'; | ||
|
||
for (int t = 1; t <= tcc; ++t) | ||
{ | ||
int k = getRand(2, 5); | ||
|
||
string ans = ""; | ||
int n = getRand(1, maxN / k) * k; | ||
for (int c = 1; c <= n; ++c) | ||
{ | ||
ans.push_back(alphabets[getRand(0, ac - 1)]); | ||
} | ||
|
||
fout << k << ' ' << ans << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
const int inf = INT_MAX / 3; | ||
|
||
int ctoi(char ch) | ||
{ | ||
return ch - 'a'; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
int ac = 26; | ||
string alphabets = "abcdefghijklmnopqrstuvwxyz"; | ||
|
||
int tcc; cin >> tcc; | ||
for (int t = 1; t <= tcc; ++t) | ||
{ | ||
int k; cin >> k; | ||
string s; cin >> s; | ||
|
||
int n = s.size(), lastMin = inf, nowMin = inf; | ||
vector<vector<int>> dp(n / k, vector<int>(ac, inf)); | ||
for (int i = 0; i <= n - 1; i += k) | ||
{ | ||
string now = s.substr(i, k), allChar = ""; | ||
vector<int> count(ac + 1, 0); | ||
|
||
for (int j = 0; j <= k - 1; ++j) | ||
{ | ||
if (count[ctoi(now[j])] == 0) | ||
{ | ||
allChar += now[j]; | ||
} | ||
++count[ctoi(now[j])]; | ||
} | ||
|
||
int tc = allChar.size(); | ||
if (i == 0) | ||
{ | ||
for (int j = 0; j <= tc - 1; ++j) | ||
{ | ||
dp[i / k][ctoi(allChar[j])] = tc; | ||
} | ||
lastMin = tc; | ||
} | ||
else | ||
{ | ||
for (int p = 0; p <= tc - 1; ++p) | ||
{ | ||
for (int q = 0; q <= tc - 1; ++q) | ||
{ | ||
if (p == q && tc > 1) continue; | ||
|
||
char head = allChar[p], tail = allChar[q]; | ||
|
||
if (dp[i / k][ctoi(tail)] == inf) dp[i / k][ctoi(tail)] = lastMin + tc; | ||
|
||
dp[i / k][ctoi(tail)] = min(dp[i / k][ctoi(tail)], dp[i / k - 1][ctoi(head)] + tc - 1); | ||
|
||
nowMin = min(nowMin, dp[i / k][ctoi(tail)]); | ||
} | ||
} | ||
|
||
lastMin = nowMin; | ||
nowMin = inf; | ||
} | ||
} | ||
|
||
cout << lastMin << '\n'; | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|