活动选择问题—贪心算法
来源:互联网 发布:php 上传图片卡住 编辑:程序博客网 时间:2024/05/21 08:58
java实现:
package 贪心算法;import java.util.ArrayList;public class 活动选择问题 {private static ArrayList<Integer> list = new ArrayList<>();private static ArrayList<Integer> list1 = new ArrayList<>();public static void main(String[] args) {// 假定输入的活动序列的完成时间已排序,且为了方便算法的初始化,//我们添加了一个虚拟活动a0;其余活动为真实活动。int s[] = {0,1,3,0,5,3,5,6,8,8,2,12};int f[] = {0,4,5,6,7,9,9,10,11,12,14,16};Recursive_Activity_selector(s, f, 0, s.length-1);System.out.println(list);Greedy_Activity_selector(s, f);System.out.println(list1);}//尾递归方法public static void Recursive_Activity_selector(int s[], int f[], int k, int n) {int m = k + 1;while(m <= n && s[m] < f[k]) {m += 1;}if (m <= n) {list.add(m);Recursive_Activity_selector(s, f, m, n);}else {return ;}}//迭代方法public static void Greedy_Activity_selector(int s[], int f[]) {int n = s.length-1;list1.add(1);int k = 1;for(int m = 2; m <= n; m++) {if(s[m] >= f[k]) {list1.add(m);k = m;}}}}
阅读全文
0 0
- 贪心算法—活动选择问题
- 贪心算法—活动选择问题
- 活动选择问题—贪心算法
- 贪心算法活动选择问题
- 贪心算法---活动选择问题
- 贪心算法-活动选择问题
- 贪心算法--活动选择问题
- 贪心算法-活动选择问题
- 《算法导论》之 贪心算法—活动选择问题
- 贪心算法解决活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法 解决 活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 活动选择问题-动态规划/贪心算法
- 贪心算法与活动选择问题
- BZOJ 3282 Tree link cut trees
- Linux正则表达式总结
- Spring MVC 复杂数据绑定
- Scala I
- pandas.DataFrame.as_matrix
- 活动选择问题—贪心算法
- ADB调试命令
- ucgui
- 职业规划
- Scala II
- 零基础简单爬虫制作(以wjyt-china企业黄页爬虫为例)(下)
- GIT 查看/修改用户名和邮箱地址
- 基于嵌入式Linux的无线路由器设计——Bridged Adapter网桥模式
- start