# 第七届蓝桥杯决赛JavaC组真题——详细答案对照(完整版)-2

## 赢球票

3

1 2 3

1

3

2 1 3

6

CPU消耗  < 1000ms

package action;
import java.util.Scanner;
public class demo {
public static int n;
public static int max = 0;
public static int[] value;
public static void getResult() {
for (int i = 0; i < n; i++) {
int[] temp = new int[n];
for (int k = 0; k < n; k++)
temp[k] = value[k];
int sum = 0;
int count = 1;
int start = i;
while (true) {
boolean judge = true;
for (int k = 0; k < n; k++)
if (temp[k] >= count) {
judge = false;
break;
}
if (judge)
break;
int j = start % n;
if (temp[j] == count) {
sum = sum + count;
temp[j] = -1;
count = 1;
} else if (temp[j] != -1)
count++;
start++;
}
max = Math.max(max, sum);
}
System.out.println(max);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
value = new int[n];
for (int i = 0; i < n; i++)
value[i] = in.nextInt();
getResult();
}
}

## E、路径之谜

（城堡的西墙和北墙内各有 n 个靶子）

0  1  2  3

4  5  6  7

8  9  10 11

12 13 14 15

4

2 4 3 4

4 3 3 3

0 4 5 1 2 3 7 11 10 9 13 14 15

CPU消耗  < 1000ms

## 碱基

1<=i1<i2<....<im<=n;

【输入格式】

DNA序列从1至n编号，每个序列中的碱基从1开始依次编号，不同的生物的DNA序列长度可能不同。

【输出格式】

【样例输入】

3 2 2

ATC

TCG

ACG

【样例输出】

2

【样例输入】

4 3 3

AAA

AAAA

AAA

AAA

【样例输出】

7

【数据规模与约定】

CPU消耗  < 1000ms

package action;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class demo {
public static int n, m, k;
public static String[] S;
public static String[] num;
public static int[] start;
public static long MOD = 1000000007;
public static long count = 0;
public static HashSet<String> result = new HashSet<String>();
public static void dfs(int step, int sum) {
if (step == n || sum >= m) {
if (sum >= m) {
ArrayList<String> set = new ArrayList<String>();
StringBuffer[] s = new StringBuffer[sum];
for (int i = 0; i < sum; i++)
s[i] = new StringBuffer("");
for (int i = 0; i < n; i++) {
if (!num[i].equals("-")) {
if (!set.contains(num[i])) {
s[set.size() - 1].append(i);
s[set.size() - 1].append(start[i]);
} else {
int j = set.indexOf(num[i]);
s[j].append(i);
s[j].append(start[i]);
}
}
}
if (set.size() == sum - m + 1) {
for (int i = 0; i < sum; i++) {
if (s[i].toString().length() == k * 2) {
if (!result.contains(s[i].toString()))
count = (count + 1) % MOD;
break;
}
}
}
}
return;
} else {
for (int i = 0; i < S[step].length(); i++) {
if (i + k <= S[step].length()) {
num[step] = S[step].substring(i, i + k);
start[step] = i;
dfs(step + 1, sum + 1);
num[step] = "-";
}
dfs(step + 1, sum);
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
k = in.nextInt();
S = new String[n];
for (int i = 0; i < n; i++)
S[i] = in.next();
num = new String[n + 1];
start = new int[n + 1];
for (int i = 0; i <= n; i++)
num[i] = "-";
dfs(0, 0);
System.out.println(count);
}
}

|
2月前

44 0
|
2月前
|

49 0
|
2月前
|

32 0
|
2月前
|
Java C语言

42 0
|
2月前
|
C语言

40 0
|
2月前

39 0
|
2月前
|

36 0
|
2月前

27 0
|
2月前

41 0
|
2月前
|
Java 测试技术 C++

50 0