package 二〇一七年三月二十四日;
public class 贪心1 {
public static void main(String[] args) {
{
int[] s =
new int[] {
0,
1,
3,
0,
5,
3,
5,
6,
8,
8,
2,
12 };
int[] f =
new int[] {
0,
4,
5,
6,
7,
9,
9,
0,
10,
11,
12,
14,
16 };
System.
out.println(RAS(s,f,
0,
11));
}
}
public static String
RAS(
int[] s,
int[] f,
int k,
int n)// k为从第k个活动到第n个活动选出最优活动
{
int m = k +
1;
while (m <= n && s[m] < f[k]) {
m = m +
1;
}
if (m <= n) {
return m +
"," + RAS(s, f, m, n);
}
else{
return null;
}
}
}