-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
32 lines (31 loc) · 863 Bytes
/
Program.cs
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
using System;
using System.Collections.Generic;
namespace SplitAString
{
class Program
{
static void Main(string[] args)
{
var s = "aa";
Console.WriteLine(MaxUniqueSplit(s));
}
static int MaxUniqueSplit(string s)
{
int max = 0;
DFS(s, 0, new HashSet<string>(), ref max);
return max;
}
static void DFS(string s, int cur, HashSet<string> record, ref int max)
{
if (cur == s.Length)
max = Math.Max(max, record.Count);
for (int i = 1; i <= s.Length - cur; i++)
{
var temp = s.Substring(cur, i);
if (!record.Add(temp)) continue;
DFS(s, cur + i, record, ref max);
record.Remove(temp);
}
}
}
}