Transportation poj1040
the way. The stations are successively numbered, city A station has number 0, city B station number m. The company runs an experiment in order to improve passenger transportation capacity and thus to increase its earnings. The train has a maximum capacity
n passengers. The price of the train ticket is equal to the number of stops (stations) between the starting station and the destination station (including the destination station). Before the train starts its route from the city A, ticket orders are collected
from all onroute stations. The ticket order from the station S means all reservations of tickets from S to a fixed destination station. In case the company cannot accept all orders because of the passenger capacity limitations, its rejection policy is that
it either completely accept or completely reject single orders from single stations.
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
ticket order consists of three integers: starting station, destination station, number of passengers. In one block there can be maximum 22 orders. The number of the city B station will be at most 7. The block where all three numbers in the first line are equal
to zero denotes the end of the input file.
Output
Sample Input
10 3 4
0 2 1
1 3 5
1 2 7
2 3 10
10 5 4
3 5 10
2 4 9
0 2 5
2 5 8
0 0 0
Sample Output
19
34
(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);
}
}
Transportation poj1040的更多相关文章
- POJ1040 Transportation
题目来源:http://poj.org/problem?id=1040 题目大意: 某运输公司要做一个测试.从A城市到B城市的一条运输线路中有若干个站,将所有站包括A和B在内按顺序编号为0到m.该路线 ...
- poj1040 Transportation(DFS)
题目链接 http://poj.org/problem?id=1040 题意 城市A,B之间有m+1个火车站,第一站A站的编号为0,最后一站B站的编号为m,火车最多可以乘坐n人.火车票的票价为票上终点 ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- 【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s repr ...
- Heavy Transportation(最短路 + dp)
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- uva301 - Transportation
Transportation Ruratania is just entering capitalism and is establishing new enterprising activiti ...
随机推荐
- Linux 软连接 & 硬链接
1.Linux链接概念Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接]硬连接指通过索引节点 ...
- 用MysQL语句怎么进行远程连接数据库
一.连接远程数据库: 1.显示密码如:MySQL 连接远程数据库(192.168.2.115),端口“3306”,用户名为“root”,密码“root” C: -u root -proot (注意第一 ...
- (九)经典_STM32_ADC多通道采样的例子
STM32 ADC多通道转换描述:用ADC连续采集11路模拟信号,并由DMA传输到内存.ADC配置为扫描并且连续转换模式,ADC的时钟配置为12MHZ.在每次转换结束后,由DMA循环将转换的数据传输到 ...
- 5.OpenStack添加镜像服务
添加镜像服务 这里是安装在控制器上 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glanc ...
- python接口自动化6-重定向(Location)【转载】
本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python%E6%8E%A5%E5%8F%A3%E8%87%AA%E5%8A%A8%E ...
- 在Laravel中使用Middleware进行身份验证
新建一个中间件: 方法写在handle中 判断用户是否登录而且是否是管理员,不是的话返回到主页 新建判断是否为管理员的方法 在kernel定义一个中间件,key是admin 注册群组路由:prefix ...
- 学习SPRING BOOT, SPRING CLOUD之Eureka和security
有意思,明天去杨浦报名了一个SPRING CLOUD沙龙, 今天再抓紧看看哈哈哈. Eureka服务端: EurekaApplication.java package com.packtpub.Eur ...
- (11)C#值类型和引用类型,堆和栈,ref和out,装箱和拆箱
一.值类型和引用类型定义 以内存中的存在方式可以把变量分成两大类型,值类型和引用类型. 值类型:系统只占用一块内存,数据直接存储在内存里. 引用类型:系统占用两块内存,一块存放地址,另一块存放实际数据 ...
- WSS3SDK之:服务器和站点架构:对象模型概览
源出处:http://www.cnblogs.com/Sunmoonfire/archive/2011/01/18/1937884.html Windows SharePoint Services提供 ...
- POJ 1274 The Perfect Stall (二分图匹配)
[题目链接] http://poj.org/problem?id=1274 [题目大意] 给出一些奶牛和他们喜欢的草棚,一个草棚只能待一只奶牛, 问最多可以满足几头奶牛 [题解] 奶牛和喜欢的草棚连线 ...