首页 > 其他 > 详细

UVa301 - Transportation

时间:2014-04-09 00:53:37      阅读:492      评论:0      收藏:0      [点我收藏+]

题目地址:点击打开链接

就是搜索订单就可以了

#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,布布扣,bubuko.com

UVa301 - Transportation

原文:http://blog.csdn.net/leizh007/article/details/23202941

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!