hdu 1381
OJ上分类里说这题是HASH,我用JAVA的TreeSet水过~
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
public static int work(String str, int N) {
int len = str.length();
if(N >= len) {
return 1;
}
TreeSet<String> ts = new TreeSet<String>();
ts.clear();
int ans = 0;
for(int i = 0; i + N <= len; i++) {
if(ts.add(str.substring(i, i + N))) {
ans ++;
}
}
return ans;
}
public static void main(String[] args) {
int T, N, NC;
String str;
Scanner cin = new Scanner(System.in);
T = cin.nextInt();
while(T-- > 0) {
N = cin.nextInt();
NC = cin.nextInt();
str = cin.next();
System.out.println(work(str, N));
}
}
}