贪心算法-经典例子

xiaoxiao2021-02-28  72

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 }; // 活动开始时间,为了方便计算加入第0个活动,不影响 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; } } }
转载请注明原文地址: https://www.6miu.com/read-66142.html

最新回复(0)