알고리즘 도론 활동 선택 문제

4215 단어 알고리즘 도론
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
// , a1 
// 
// 
vector<int>result;
vector<int> ActiveSelect(vector<int> start, vector<int>end, int k, int n)
{
    int m = k + 1;//k ,m 
    while (m <= n&&start[m] < end[k])
        m++;// , 
    if (m <= n)
    {
        result.push_back(m);// 
        ActiveSelect(start, end, m, n);// 
    }
    return result;
}
// 
vector<int> ActiveSelect1(vector<int>start, vector<int>end)
{
    result.push_back(1);
    int k = 1;
    for (int m = 2; m <end.size(); m++)
    {
        if (start[m]>=end[k])
        {
            result.push_back(m);
            k = m;
        }
    }
    return result;
}
int main()
{
    vector<int>start = {0,1,3,0,5,3,5,6,8,8,2,12 };
    vector<int>end = { 0,4,5,6,7,8,9,10,11,12,14,16 };
    vector<int>result;
    //result = ActiveSelect(start, end, 0, 11);
    result = ActiveSelect1(start, end);
    for (auto c : result)
        cout << c << endl;
}

좋은 웹페이지 즐겨찾기