UVA 301 - Transportation

LO611 Transportation 立即下载

Transportation 

Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transportation company TransRuratania is starting a new express train from city A to city B with several stops in the stations on 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

The input file is divided into blocks. The first line in each block contains three integers: passenger capacity n of the train, the number of the city B station and the number of ticket orders from all stations. The next lines contain the ticket orders. Each 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

The output file consists of lines corresponding to the blocks of the input file except the terminating block. Each such line contains the biggest possible total earning.

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

================================

把搜索之前的状态保存在save数组中,每次回溯调回之前的状态


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int n,sta,p,maxsum,vis[11];

struct ticket
{
    int start;
    int end;
    int num;
    int money;
}s[111];

bool check(int cur)
{
    for(int i=s[cur].start;i<s[cur].end;i++)
    {
        vis[i]+=s[cur].num;
        if(vis[i]>n)
            return 0;
    }
    return 1;
}

void dfs(int cur,int sum)
{
    //cout<<"cur="<<cur<<endl;
    if(cur==p)
    {
        if(sum>maxsum)
            maxsum=sum;
        //cout<<sum<<endl;
        return;
    }
    dfs(cur+1,sum);
    int save[11];
    memcpy(save,vis,sizeof(save));
    if(check(cur))
    {
        dfs(cur+1,sum+s[cur].money);
    }
    memcpy(vis,save,sizeof(save));
    return;
}

int main()
{
    while(~scanf("%d%d%d",&n,&sta,&p))
    {
        if(n==0&&sta==0&&p==0) break;
        memset(vis,0,sizeof(vis));
        maxsum=-1;
        for(int i=0;i<p;i++)
        {
            scanf("%d%d%d",&s[i].start,&s[i].end,&s[i].num);
            s[i].money=s[i].num*(s[i].end-s[i].start);
        }
        dfs(0,0);
        printf("%d\n",maxsum);
    }
    return 0;
}


OpenClaw实战系列06:持久记忆与RAG知识库构建——让AI真正“记住”你 本文介绍了OpenClaw AI助理的持久记忆与RAG知识库构建功能。OpenClaw采用"文件即真理"的独特设计,所有记忆都以Markdown文件形式存储,支持直接编辑和Git版本管理。记忆系统分为三层:长期精炼记忆(MEMORY.md)、日常日志(按日期存储)和归档记忆。文章详细说明了环境配置步骤,包括安装必要组件、创建目录结构、设置API密钥,并提供了OpenClaw主配置文件的完整参数说明。该系统实现了跨会话、跨平台的持久化记忆,使AI助理能真正理解用户需求。 阅读详情

相关推荐

【5G】5G 核心网(5GC)基本架构

本文旨在科普5G核心网相关知识...

Learning makes me happy (0^◇^0) 4万+

uva-301 - Transportation

Transportation  Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transportation company TransRuratania is star

写东西的地方 1002

Web渗透(一)CRLF注入简介

CRLF注入简介1、基础知识2、原理分析3、漏洞挖掘4、防御手段5、CRLF Payload: 1、基础知识 HTTP报文结构 从上图可以看到:HTTP报文由三部分组成:状态行、首部、主体。 可以看到状态行和首部中的每行都是以回车符(\r,%0d,CR)和换行符(\n,%0a,LF)结束。 十六进制编码分别为0x0d和0x0a,URL编码为%0D和%0A 这是因为HTTP规范中行应该使用CRLF结束。另外,首部和主体由两个CRLF分隔。 2、原理分析 CRLF是 “ 回车+换行 ”(\r\n)的简称。

weixin_39157582的博客 6821

UVa 301 - Transportation

301 - Transportation 4584 32.83% 1338 76.08% 题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=2

D_Double's Journey 1761

神经网络学习笔记-波尔兹曼(Boltzmann)机

Boltzmann机是一种反馈随机神经网络 两种输出状态,单极性0或1。输出状态的取值根据概率统计法则决定,这种概率统计法则类似Boltzmann分布,部分反馈 它在神经元状态变化中引入了统计概率,网络的平衡状态服从Boltzmann分布,网络运行机制基于模拟退火算法。 离散Hopfield神经网络+模拟退火+隐单元=Boltzman机 DHNN全反馈,转移函数:符号函数 BM机网络拓扑...

求易学堂的博客 2614

数学建模 种群竞争模型 学习笔记

模型背景 应用场景 种群竞争模型 例如 s1=0.5,则表示对于供养甲的资源来讲,单位数量的乙的消耗为单位数量的甲的0.5倍,即表示乙对于该资源的占有能力是甲的0.5倍(即竞争力弱) 仿真结果及分析 (1)设置自然增长率 r1=r2=1 (2)改变自然增长率 r1=r2=0.3 (3)修改甲和乙的最大容量 n1=10000, n2=100 (4)修改甲和乙的初始数量 x1=10, x...

Test_tju的博客 2028

UVA_301_Transportation

Transportation  Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transportation company TransRuratania is starti

OTTFF的博客 1112

YOLO26优化:注意力魔改 | 用于微小目标检测的上下文增强和特征细化网络ContextAggregation,助力小目标检测,暴力涨点

用于微小目标检测的上下文增强和特征细化网络ContextAggregation,助力小目标检测

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 490

301UVA地铁运输

注意:人数限制是指从站到站的人数,不是站台上的人数 #include #include int cpct,numsta,numord; int maxmoney; int sta[10]; int start[25]; int end[25]; int psg[25]; void dfs(int order, int money) { if(money > maxmoney) { max

howlowl 263

Arcgis建筑面shp由DSM和DEM获取高度拉伸并可视化

Arcgis建筑面shp由DSM和DEM获取高度拉伸并可视化

yilvyangguang520的博客 3991

网络流量异常信息分析方法研究

本课题针对网络安全中网络流量异常的分析方法进行研究,提出一种基于机器学习和深度学习的异常检测算法。该算法采用卷积神经网络(CNN)和长短时记忆神经网络(LSTM)结合的方式,通过训练得到二分类模型,从而实现对网络流量异常的检测。随着互联网的飞速发展,网络攻击事件日益增多,网络安全问题成为了亟待解决的问题之一。常见的网络攻击手段包括 DDoS 攻击、SQL 注入、XSS 攻击等,这些攻击手段可能导致网络系统发生异常,给网络运维、数据安全带来极大的挑战。

肥晨开发的学习之路 1035

UVA301- Transportation

题意:有个城市,从起始站到末站,一共有n个车站。车的载客量是有限制的,有m个订单,要求运输企业的利润最大化,也就是说,订单要么一整个接受,要么拒绝 思路:利用DFS回溯,对于一个订单而言,要么接受,要么就是拒绝,记录每条订单的起始站到末站的人数,不能超过最大载客量 #include #include int p, num, order, max; int cnt[100]; struct

懒人一枚。 865

把大表拆成更好用的“小仓库”:SAP HANA 表分区设计、分区裁剪与内存代价全解析

摘要:本文深入解析SAP HANA分区技术的核心价值与实现策略。作为内存数据库的"手术刀",分区通过将逻辑表横向切分为独立物理容器,显著提升并行计算能力与查询效率。重点探讨了三种分区类型(Range、Hash、Round-robin)的适用场景,以及分区裁剪的优化原理与前提条件。特别指出分区设计需要平衡查询模式与数据分布,并揭示了分区对内存占用的双向影响机制:既可能因字典复制增加消耗,也可能因数据纯度提升压缩率。通过电商订单表等实际案例,展示了合理分区如何将分钟级报表优化至秒级响应。文章

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1650

UVA 301 Transportation

UVA 301 Transportation题目大意:列车运人,获利最大的问题,第一行输入三个值,分别是限制人数,站点数,订单数t,然后以下t行是订单信息,每个订单包含3个值前俩个代表从第x站到第y站,第三个数是人数,获利=人数*(y - x)解题思路:回溯,无非就是一个部车开过去是否接这个单,每次判断是否能接这个单,递归判断接与不接,比较最大值就行#include <stdio.h> #inclu

ZeroLH00的博客 423

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

UVA 301 Transportation 。。有点需要思考的回溯、、

UVA 301 Transportation  Transportation  Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transp

Remilia's 1920

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

uva 301 Transportation

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=237 题目描述:  Transportation  Ruratania is just ent

心之所向,无惧无悔! 1648

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

UVa 301 - Transportation

题目链接:UVa 301 - Transportation 回溯,注意这个题是一个方向走的,不回头。写了两份代码,第一份WA,换了种思路,第二份AC了,都贴出来,以后再研究研究。 /** WA */ #include #include #include using namespace std; const int MAX_N = 22 + 5; int m,n,c; struct or

fobdddf的专栏 643

UVa 301 Transportation

本文研究了列车订单选择问题,提出了一种基于深度优先搜索的优化算法。该问题要求在列车容量限制下,选择接受或拒绝各站订单以最大化收益。算法通过预处理订单收益、排序优化和剪枝策略,有效减少了搜索空间。关键点包括:1) 按起始站和终点站排序订单;2) 动态维护下车乘客数;3) 利用剩余收益上界剪枝。实验表明,该方法在订单数≤22、车站数≤7时高效可行,能在有限时间内求得最优解。算法正确性由三个引理保证,复杂度分析显示其实际运行效率远优于理论最坏情况。

寂静山林 405

UVA 301 Transportation

UVA-301题意:给出车量承载人数,城市数,订单数,以及每个订单的起始城市,终点城市和人数。城市的到达顺序0->1->2->……>n,每个人每坐到下一个城市需要1个花费,求车子最多能获得多少钱。 解题思路:枚举每个订单接不接,起始站的num[star]+= order_number[i]; 终点站 num[end]-=order_number[i]。然后从0开始一路累加num[i],到城市i,前

QzNarsh的博客 425

uva 301 - Transportation

题目大意: 给出一些

qqcyclone的专栏 629

uva 301 - Transportation

此题大意:给定n个车站,每个车站有到不同目的地的订单,最多有22个订单,每个订单的总额为总的人数乘以经过的站,问最大收益。  首先想到的思路是直接枚举,使用回朔算法,结果过了但是时间是2.6秒,然后使用了了已接受订单的总额 + 后面所有订单的总额 最后看了一下,时间可能浪费在使用了vector和next——permutation上了。 附上参考博客: http://www

最爱她! 365

UVA - 301 Transportation

题目大意:给你一辆车的最多载客数,站台书

静静地码 711

uva301 - Transportation

题意就是给出一些station 然后一辆公车有人数限制。 问你求出最大的收益 先对起点排个序。。然后就不用vis数组直接一个个递归下去。。一开始一直WA因为在main里没有枚举每个点。。。蛋疼 题目:    Transportation Ruratania is just entering capitalism and is ...

aiezhen1717的博客 171
上一篇: UVA 539 - The Settlers of Catan(深搜 回溯)
下一篇: UVA 10344 - 23 Out of 5(回溯)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值