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 ...
随机推荐
- css去掉点击连接时所产生的虚线边框技巧兼容符合w3c标准的浏览器
解决方法: 1.在css中加上outline:none; 代码如下: a.fontnav { text-align:left;color:#555; text-decoration:none; out ...
- js限定内容的溢出滚动(offset,style.left)
1. .html: <div class="test" style="position: relative;"> <ul id="c ...
- 题(NOIP模拟赛Round #10)
题目描述: 有一张的地图,其中的地方是墙,的地方是路.有两种操作: 给出个地点,询问这个地点中活动空间最大的编号.若询问的位置是墙,则活动空间为:否则活动空间为询问地点通过四联通能到达的点的个数.如果 ...
- 【一】ODB - C++ 访问数据库的利器--Hello World On Windows(Version-24)
本文以MySQL数据库为例,其他数据类似. 官方文档和下载 ODB官方首页 官方开发者说明书(开发教程) 安装下载首页(下载与安装教程Windows/Linux) Windows安装步骤(都是英 ...
- centos编译安装vim并支持lua
系统环境:centos6.5 x86 (basic server) 1.安装编译环境. # yum groupinstall "Development Tools" 2.安装vim ...
- HTML,DIV+CSS,js,JQ,UI-WEB前端设计经验
目前比较全的CSS重设(reset)方法总结 在当今网页设计/开发实践中,使用CSS来为语义化的(X)HTML标记添加样式风格是重要的关键.在设计师们的梦想中都存在着这样的一个完美世界:所有的浏览 ...
- MFC学习之EDIT控件初始化
//四种方法为EDIT控件初始化 //调用系统API HWND hEidt = ::GetDlgItem(m_hWnd,IDC_EDIT1); ::SetWindowText( ...
- Selenium2+python自动化1-环境搭建【转载】
前言 目前selenium版本已经升级到3.0了,网上的大部分教程是基于2.0写的,所以在学习前先要弄清楚版本号,这点非常重要.本系列依然以selenium2为基础,目前selenium3坑比较多,暂 ...
- 部署站点支持Https访问的方法
1.申请公钥和私钥,放到服务器 2.编辑default配置文件 改为 加上证书路径 ps:泛域名支持admin.xxx.com.demo.xxx.com等等,而免费的Let's Encrypt仅支持w ...
- AC日记——最小正子段和 51nod 1065
最小正子段和 思路: 找最小的大于0的sum[j]-sum[i](j>i): 高级数据结构(splay)水过: 来,上代码: #include <cstdio> #include & ...