貪心算法——活動安排問題


#include "stdafx.h"
#include <iostream>
using namespace std;

void GreedySelector1(int n, int s[], int f[])
{
int j = 0;
cout << 1 << endl;
for (int i = 1; i <= n - 1; i++)
{
if (s[i] >= f[j])//開始時間大於結束時間,說明它在后面
{
//A[i]=true;
j = i +1;
cout << j << endl;
}
}
}
//活動安排問題——貪心算法實現
void main()
{
//void GreedySelector(int n,Type s[],Type f[],bool A[]);
bool a[11];
int s[] = { 1, 3, 0, 5, 3, 5, 6, 8, 8, 2, 12 }; //存放每個活動的開始時間
int f[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };//每個活動的結束時間
GreedySelector1(11, s, f);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM