`
473687880
  • 浏览: 535125 次
文章分类
社区版块
存档分类
最新评论

Transportation UVA301

 
阅读更多



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 numberm. The company runs an experiment in order to improve passenger transportation capacity and thus to increase its earnings. The train has a maximum capacitynpassengers. 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 capacitynof 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
这道题用数组标记回溯会超时。我第一次就因为这个超时了,改成现在这种方法就AC了
#include<iostream>
#include<cstring>

using namespace std;

int order[30][5];
int vis[30],place[10];
int maxnum,n,m,t;

int judge(int pos)
{
    int tag=1;
    int k;
    for(k=order[pos][0];k<order[pos][1];k++)
    {
        if(order[pos][2]+place[k]>n)
        {
            tag=0;
            break;
        }
    }
    return tag;
}

void dfs(int pos,int ans)
{
    if(ans>maxnum) maxnum=ans;
    if(pos>=t) return;
    int i;
    if(judge(pos))
    {
        for(i=order[pos][0];i<order[pos][1];i++)
            place[i]=place[i]+order[pos][2];
        dfs(pos+1,ans+(order[pos][1]-order[pos][0])*order[pos][2]);
        for(i=order[pos][0];i<order[pos][1];i++)
            place[i]=place[i]-order[pos][2];
    }
    dfs(pos+1,ans);
}

int main()
{
    while(cin>>n>>m>>t&&(n||m||t))
    {
        int i,j;
        if(!n||!m||!t)
        {
            cout<<"0"<<endl;
            continue;
        }
        memset(order,0,sizeof(order));
        memset(place,0,sizeof(place));
        for(i=0;i<t;i++)
            cin>>order[i][0]>>order[i][1]>>order[i][2];
        maxnum=0;
        dfs(0,0);
        cout<<maxnum<<endl;
    }
    return 0;
}


分享到:
评论

相关推荐

    Transportation

    标题“Transportation”和描述中的信息非常简洁,主要聚焦在运输这一主题上,但并没有提供具体的技术细节。然而,从标签“字体”来看,我们可以推测这可能与一款名为“Transportation”的字体设计有关。通常,.TTF...

    transportation

    transportation

    Transportation Research Board论文

    从给定的“Transportation Research Board论文”文件中,我们可以提炼出多个关键的IT与交通运输研究结合的知识点,这些论文涵盖了交通管理、设计、环境、经济、数据分析等多个方面,展现了IT技术在交通运输领域的...

    Intelligent Transportation Systems.pdf

    智能交通系统(Intelligent Transportation Systems, ITS)是利用信息技术、通信技术、数据处理技术以及控制技术等,对交通进行高效管理、优化运行和提升服务的一种综合系统。在现代社会,快速、可靠、安全且便捷的...

    Air Transportation Modeling and Sim

    航运模型 Air Transportation Modeling and Sim

    Introduction to Intelligent Systems in Traffic and Transportation

    This book aims at giving a broad introduction into the basic but relevant concepts related to transportation systems, targeting researchers and practitioners from computer science and information ...

    AI in Transportation_KDD2018_Tutorial_final.pdf

    -Challenges and opportunities in transportation AI --Overview of urban transportation --The emerging challenges in transportation AI -AI applications in transportation -Data and tools for ...

    Book_transportation_cn.pdf

    文档标题“Book_transportation_cn.pdf”表明这是一本关于Oracle技术的中文教材。在描述中提到这本书“讲的还可以”,暗示书中内容具有一定的实用性和可读性,可以作为学习Oracle的一本参考教材。 ### Oracle 技术...

    Introducing Transportation Management in SAP S4HANA.zip

    sap press doc 解压密码:abap_developer

    ajax_transportation_methods 官方文档

    **Ajax 传输方法详解** Ajax(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。这种技术的核心在于XMLHttpRequest对象,它允许JavaScript与服务器进行异步数据...

    SAP TM(Transportation Management)基础设置

    ### SAP TM(Transportation Management)基础设置 #### 知识点概述 SAP TM(Transportation Management)是SAP公司开发的一款专为物流与运输管理设计的企业应用解决方案。该系统旨在帮助企业实现对整个物流过程的...

    [2018]Deep Reinforcement Learning for Intelligent transportation predictoin.pdf

    Intelligent Transportation Systems (ITSs) are envisioned to play a critical role in improving traffic flow and reducing congestion, which is a pervasive issue impact ing urban areas around the globe. ...

    GIS AND TRANSPORTATION: STATUS AND CHALLENGES good child

    ### GIS与交通运输:现状与挑战 #### 摘要概览与核心观点 本文由Michael F. Goodchild撰写,深入探讨了地理信息系统(GIS)在交通运输领域的应用和发展历程。作者将GIS-T的发展划分为三个阶段:地图视图(Map View)...

    Research on Intelligent Transportation System Technologies and Applications

    随着信息技术的快速发展,智能交通系统(Intelligent Transportation Systems, ITS)已成为提高城市交通效率、保障交通安全的关键领域之一。自20世纪70年代初以来,ITS的发展使得人、车、路之间的联系更加紧密和谐,...

    Iconshock_Transportation.rar

    《Iconshock Transportation图标库详解》 Iconshock Transportation.rar是一个包含丰富交通运输主题图标的压缩包,它为设计师和开发者提供了大量的视觉元素,用于创建与交通相关的应用、网站或者图形设计项目。这些...

    c-language-transportation.zip_transportation

    标题 "c-language-transportation.zip_transportation" 暗示我们关注的是使用C语言处理运输相关的数据或信息。描述中提到的任务是输入一行字符,并对其中的数字、字母、空格和其他字符进行计数,同时涉及到函数的...

    Transportation运输.ppt

    Transportation运输.ppt

    tcp.zip_transportation

    例如,在"tcp.zip_transportation"中可能包含的详细步骤,解释了如何通过交换这些特定的TCP段来建立和确认连接。 其次,TCP使用序列号和确认应答来保证数据的有序传输。每个TCP段都有一个序列号,标识该数据段在...

    ajax_transportation_methods.ppt

    **Ajax 技术详解** Ajax(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。这种技术通过JavaScript实现,利用XMLHttpRequest对象作为客户端与服务器之间的通信...

Global site tag (gtag.js) - Google Analytics