贪心算法 解决 活动选择问题
来源:互联网 发布:知乎目标用户 编辑:程序博客网 时间:2024/06/07 00:12
转自:http://download.csdn.net/download/march_on/3625421
</pre><pre code_snippet_id="440959" snippet_file_name="blog_20140802_4_3506359" name="code" class="cpp">#define GREEDY_RECURIVE#ifdef GREEDY_RECURIVE#include <iostream>#include <iomanip>#include <vector>using namespace std;void recursive_activity_selector( const int started[], const int finished[],vector<int>& result, int i,int j);//对vector类型要传引用的!void greedy_activity_selector( const int started[], const int finished[],vector<int>& result, int i,int j); int main( void ){const int activityNum = 11;int started[] = { -1,1,3,0,5,3,5,6,8,8,2,12,INT_MAX };int finished[] = { 0,4,5,6,7,8,9,10,11,12,13,14,INT_MAX };vector<int> result;#ifdef RECURIVErecursive_activity_selector( started, finished, result, 0, activityNum+1); #elsegreedy_activity_selector( started, finished, result, 0, activityNum+1); #endiffor( vector<int>::iterator iter = result.begin(); iter != result.end(); ++iter )cout << setw(3) << *iter ;return 0;}void recursive_activity_selector( const int started[], const int finished[],vector<int>& result, int i,int j){if( i >= j )return;int l;for( l = i+1; l < j; ++l ){if( started[l] >= finished[i] && finished[l] <= started[j] ) {result.push_back(l);break;}}recursive_activity_selector( started, finished, result, l, j );}void greedy_activity_selector( const int started[], const int finished[], vector<int>& result, int i, int j ){int l;for( l = i+1; l < j; ++l ){if( started[l] >= finished[i] && finished[l] <= started[j] ){result.push_back(l);i = l;}}}#endif
输出结果
1 4 8 11
0 0
- 贪心算法解决活动选择问题
- 贪心算法 解决 活动选择问题
- 贪心算法活动选择问题
- 贪心算法---活动选择问题
- 贪心算法-活动选择问题
- 贪心算法--活动选择问题
- 贪心算法-活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法之活动选择问题
- 贪心算法—活动选择问题
- 活动选择问题-动态规划/贪心算法
- 贪心算法与活动选择问题
- 贪心算法—活动选择问题
- 贪心算法例题:2073活动选择问题
- 活动选择问题—贪心算法
- 在mac下面获取IP地址的方法
- 迷你播放器--第一阶段(2)--退出时自动最小化(不是关闭),增加当前播放曲目的跑马灯效果
- live555 source
- [POJ 4001-4010][2011 Asia Fuzhou Regional Contest]2011 ACM 福州赛区现场赛题解(不断更新)
- 哈夫曼编码
- 贪心算法 解决 活动选择问题
- Java多线程总结之由synchronized说开去
- Mybatis_review之配置文件中的properties节点内容说明
- Make Photo Magic 使用Aviary SDK 进行图片编辑开发,功能非常强大!!!!(Aviary SDK安装说明)
- javafx tableview 绑定字段的两种方法
- Python开发问题 还要凑齐1打问题,陆续ING。。。
- AndroidManifest.xml配置文件详解
- 韩顺平PHP学习视频笔记整理001html简介1
- poj 3696 The Luckiest number(欧拉函数)