Transportation poj1040
来源:互联网 发布:mac怎么改字体 编辑:程序博客网 时间:2024/06/14 20:00
Write a program which for the given list of orders from single stations on the way from A to B determines the biggest possible total earning of the TransRuratania company. The earning from one accepted order is the product of the number of passengers included in the order and the price of their train tickets. The total earning is the sum of the earnings from all accepted orders.
Input
Output
Sample Input
10 3 40 2 11 3 51 2 72 3 1010 5 43 5 102 4 90 2 52 5 80 0 0
Sample Output
1934
(1)题意:火车运输,n个车站编号0-(n-1),之间有很多订单,问你,最大收益是多少?火车的载客量一定,车上的人不能超过这个数,先给你3个数,火车载客量m、车站数n、订单数p。然后p行数据,每行3个数,分别代表订单的起点、终点和人数。
(2)解法:先对订单进行排序,按起点站先后排,若一样,按终点排,然后对订单进行深度搜索。剪枝:遇到人数超过载客量的时候,就返回。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
struct Rac{
int start;
int end1;
int num;
}p[30];
int lode,station,order;
int maxmoney;
int people[30]={0}; //表示到i站的人数,,people[2]表示站1到站二的人数
void DFS(int ding,int money) //第几订单,钱;
{
if(ding==order)
{
maxmoney=max(maxmoney,money);
return ;
}
int i,j,flag=1;
for(i=p[ding].start+1;i<=p[ding].end1;i++) //判断人人数是否超了
{
if(people[i]+p[ding].num>lode)
{
flag=0;
break;
}
}
if(flag==1) //第ding条订单符合条件~~
{
for(i=p[ding].start+1;i<=p[ding].end1;i++) people[i]=people[i]+p[ding].num; //start到end站都加上该订单人数
DFS(ding+1,money+(p[ding].end1-p[ding].start)*p[ding].num);
for(i=p[ding].start+1;i<=p[ding].end1;i++) people[i]=people[i]-p[ding].num;//恢复
}
DFS(ding+1,money); //不要该订单;
}
bool cmp(struct Rac a,struct Rac b)
{
if(a.start!=b.start) return a.start<b.start;
else return a.end1<b.end1;
}
int main()
{
//freopen("test.txt","r",stdin);
while(scanf("%d %d %d",&lode,&station,&order),lode!=0||station!=0||order!=0)
{
int i;
for(i=0;i<order;i++) scanf("%d %d %d",&p[i].start,&p[i].end1,&p[i].num);
sort(p,p+order,cmp);
// for(i=0;i<order;i++) printf("%d %d %d\n",p[i].start,p[i].end1,p[i].num);
memset(people,0,sizeof(people));
maxmoney=0;
DFS(0,0);
printf("%d\n",maxmoney);
}
}
- <poj1040>Transportation
- POJ1040 Transportation
- Transportation poj1040
- poj1040
- 301Transportation(****)
- 301 - Transportation
- UVA301- Transportation
- uva301 - Transportation
- UVaOJ301 - Transportation
- UVA301- Transportation
- uva301 - Transportation
- [toj1003]Transportation
- Intelligent Transportation
- HDU3667.Transportation
- Heavy Transportation
- Heavy Transportation
- POJ_3452_Railway Transportation
- Goods transportation
- 安装Navicat Premium
- follow your heart
- Android的生命周期
- 计算化学领域的黑科技
- js获取点击对象并设值
- Transportation poj1040
- Android Recovery Ui 分析
- qsort 模板
- Scala详解-----------控制结构和函数
- button的OnClickListener的三种实现方
- Python是什么
- web001-html,css,js
- PHP libcurl使用总结
- vpngate 的使用