贪心算法——活动分配

#include 
using namespace std;
#define N 11
int s[N + 1] = { 0,1,3,0,5,3,5,6,8,8,2,12 };
int f[N + 1] = { 0,4,5,6,7,8,9,10,11,12,13,14 };
//递归实现
void Recursive_Activity_Selector(int s[], int f[], int i, int n)
{
    int m = i + 1;
    while (m <= n && s[m] < f[i])
        m = m + 1;
    if (m <= n)
    {
        cout << "资源分配给任务" << m << endl;
        Recursive_Activity_Selector(s, f, m, n);
    }
}
//贪心算法
void greeedy_a_s(int s[], int f[])
{
    int left = 1;
    int right;
    cout << "分配给任务1" << endl;
    for (right = 2; right <= N; right++)
    {
        if (s[right] >= f[left])
        {
            cout << "分配给任务"<

你可能感兴趣的:(贪心算法——活动分配)