递归贪心算法c++源码实现

  • Post author:
  • Post category:其他


//递归贪心算法的实现
//test1.cpp
#include <iostream>
using namespace std;

void RecursiveActivitySeletor(int* s,int *f,int i,const int n)
{
	int m=i+1;
	while(m<=n&&s[m]<f[i])
		m+=1;
	if (m<=n)
	{
		cout<<"a["<<m<<"]"<<"  ";
		RecursiveActivitySeletor(s,f,m,n);
	}

}

int main()
{
	int i,n=11;
	int s[]={0,1,3,0,5,3,5,6,8,8,2,12};
	int f[]={0,4,5,6,7,8,9,10,11,12,13,14};
	RecursiveActivitySeletor(s,f,0,n);
	cout<<endl;

	return 0;
}




版权声明:本文为xiaofei2010原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。