正在加载图片...
清华大学出版社 TSINGHUA UNIVERSITY PRESS 4.1活动安排问题 在下面所给出的解活动安排问题的贪心算法 greedySelector public static int greedySelector(int [s, int[ f, boolean aD) int n=s length-1 all-true for(int 1=2; K<=n; i++)& 各活动的起始时间和结 if(si]>=fDi 束时间存储于数组s和f all-true 中且按结束时间的非减 序排列 count++ else ai]=false return count6 4.1 活动安排问题 在下面所给出的解活动安排问题的贪心算法greedySelector : • public static int greedySelector(int [] s, int [] f, boolean a[]) • { • int n=s.length-1; • a[1]=true; • int j=1; • int count=1; • for (int i=2;i<=n;i++) { • if (s[i]>=f[j]) { • a[i]=true; • j=i; • count++; • } • else a[i]=false; • } • return count; • } 各活动的起始时间和结 束时间存储于数组s和f 中且按结束时间的非减 序排列
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有