您的位置:首页 > 其它

活动选择问题(算法导论第十六章贪心算法)

2011-10-28 10:01 281 查看
#include <IOSTREAM>
#include<VECTOR>
using namespace std;
void recursive(int s[],int f[],int i,int n,vector<int> &h)
{

int m=i+1;
while (m<=n&&s[m]<f[i])
{
m=m+1;
}
if (m<=n)
{
h.push_back(m);
//	h.insert(h.end(),m);
recursive(s,f,m,n,h);

}
}
int main()
{

int s[12]={0,1,3,0,5,3,5,6,8,8,2,12};
int f[12]={0,4,5,6,7,8,9,10,11,12,13,14};
vector<int> h;//h为存放活动的向量
recursive(s,f,0,11,h);
vector<int>::iterator t;
for (t=h.begin();t!=h.end();t++)
{
if (t!=h.end()-1)
{
cout<<*t<<" ";
}
else
{
cout<<*t<<endl;
}

}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息