概述
题目地址:点击打开链接
就是搜索订单就可以了
#include <iostream>
#include <cstring>
using namespace std;
struct Station
{
int start;
int end;
int num_of_people;
};
const int maxsize = 25;
Station Orders[maxsize];
int people_num_of_station[10];
int max_people,num_of_station,num_of_orders;
int ans;
bool check()
{
for(int i=0;i<=num_of_station;++i)
if(people_num_of_station[i]>max_people)
return false;
return true;
}
void dfs(int val,int sum)
{
if(sum>ans)
ans=sum;
for(int i=val;i<num_of_orders;++i)
{
for(int j=Orders[i].start;j<Orders[i].end;++j)
people_num_of_station[j]+=Orders[i].num_of_people;
if(check())
dfs(i+1,sum+Orders[i].num_of_people*(Orders[i].end-Orders[i].start));
for(int j=Orders[i].start;j<Orders[i].end;++j)
people_num_of_station[j]-=Orders[i].num_of_people;
}
}
int main()
{
while(cin>>max_people>>num_of_station>>num_of_orders)
{
if(max_people==0&&num_of_station==0&&num_of_orders==0)
break;
for(int i=0;i<num_of_orders;++i)
cin>>Orders[i].start>>Orders[i].end>>Orders[i].num_of_people;
ans=-1;
memset(people_num_of_station,0,sizeof(people_num_of_station));
dfs(0,0);
cout<<ans<<endl;
}
return 0;
}
最后
以上就是漂亮奇异果为你收集整理的UVa301 - Transportation的全部内容,希望文章能够帮你解决UVa301 - Transportation所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复