P3431 [POI2005]AUT-The Bus

题目描述

The streets of Byte City form a regular, chessboardlike network - they are either north-south or west-east directed. We shall call them NS- and WE-streets. Furthermore, each street crosses the whole city. Every NS-street intersects every WE- one and vice versa. The NS-streets are numbered from 11 to nn, starting from the westernmost. The WE-streets are numbered from 11 to mm, beginning with the southernmost. Each intersection of the ii'th NS-street with the jj'th WE-street is denoted by a pair of numbers (i,j)(i,j) (for 1\le i\le n1≤i≤n, 1\le j\le m1≤j≤m).

There is a bus line in Byte City, with intersections serving as bus stops. The bus begins its itinerary by the (1,1)(1,1)intersection, and finishes by the (n,m)(n,m) intersection. Moreover, the bus may only travel in the eastern and/or northern direction.

There are passengers awaiting the bus by some of the intersections. The bus driver wants to choose his route in a way that allows him to take as many of them as possible. (We shall make an assumption that the interior of the bus is spacious enough to take all of the awaiting passengers, regardless of the route chosen.)TaskWrite a programme which:

reads from the standard input a description of the road network and the number of passengers waiting at each intersection,finds, how many passengers the bus can take at the most,writes the outcome to the standard output.

Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 到 m编号. 每个路口用两个数(i, j) 表示(1 <= i <= n, 1 <= j <= m). Byte City里有一条公交线, 在某一些路口设置了公交站点. 公交车从 (1, 1) 发车, 在(n, m)结束.公交车只能往北或往东走. 现在有一些乘客在某些站点等车. 公交车司机希望在路线中能接到尽量多的乘客.帮他想想怎么才能接到最多的乘客.

输入输出格式

输入格式:

The first line of the standard input contains three positive integers nn, mm and kk - denoting the number of NS-streets, the number of WE-streets and the number of intersections by which the passengers await the bus, respectively (1\le n\le 10^91≤n≤10​9​​, 1\le m\le 10^91≤m≤10​9​​, 1\le k\le 10^51≤k≤10​5​​).

The following kk lines describe the deployment of passengers awaiting the bus, a single line per intersection. In the (i+1)(i+1)'st line there are three positive integers x_ix​i​​, y_iy​i​​ and p_ip​i​​, separated by single spaces, 1\le x_i\le n1≤x​i​​≤n,1\le y_i\le m1≤y​i​​≤m,1\le p_i\le 10^61≤p​i​​≤10​6​​ . A triplet of this form signifies that by the intersection(x_i,y_i)p_i(x​i​​,y​i​​)p​i​​ passengers await the bus. Each intersection is described in the input data once at the most. The total number of passengers waiting for the bus does not exceed 1\ 000\ 000\ 0001 000 000 000.

输出格式:

Your programme should write to the standard output one line containing a single integer - the greatest number of passengers the bus can take.

输入输出样例

输入样例#1:

  1. 8 7 11
  2. 4 3 4
  3. 6 2 4
  4. 2 3 2
  5. 5 6 1
  6. 2 5 2
  7. 1 5 5
  8. 2 1 1
  9. 3 1 1
  10. 7 7 1
  11. 7 4 2
  12. 8 6 2
输出样例#1:

  1. 11
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. #define maxn 5000
  5. int n,m,k,map[maxn][maxn],x,y,dp[maxn][maxn];
  6. int main(){
  7. scanf("%d%d%d",&n,&m,&k);
  8. int x,y,z;
  9. for(int i=;i<=k;i++){
  10. scanf("%d%d%d",&x,&y,&z);
  11. map[x][y]=z;
  12. }
  13. for(int i=;i<=n;i++){
  14. for(int j=;j<=m;j++){
  15. dp[i][j]=max(dp[i-][j],dp[i][j-])+map[i][j];
  16. }
  17. }
  18. cout<<dp[n][m];
  19. }

30分 O(nm)

洛谷P3431 [POI2005]AUT-The Bus的更多相关文章

  1. 树状数组 二维偏序【洛谷P3431】 [POI2005]AUT-The Bus

    P3431 [POI2005]AUT-The Bus Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 ...

  2. 洛谷 P3431:[POI2005]AUT-The Bus(离散化+DP+树状数组)

    题目描述 The streets of Byte City form a regular, chessboardlike network - they are either north-south o ...

  3. 洛谷 P3420 [POI2005]SKA-Piggy Banks

    P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...

  4. 洛谷 P3419 [POI2005]SAM-Toy Cars

    P3419 [POI2005]SAM-Toy Cars 题目描述 Johnny is a little boy - he is only three years old and enjoys play ...

  5. 洛谷 P3420 [POI2005]SKA-Piggy Banks 题解

    蒟蒻的第二篇题解 嗯,直接进入正题 先告诉你们这是并查集,好吧,标签上面有,再来分析这为什么是并查集. 根据题意: 每一个存钱罐能够用相应的钥匙打开或者被砸开,Byteazar已经将钥匙放入到一些存钱 ...

  6. 【模板】矩阵快速幂 洛谷P2233 [HNOI2002]公交车路线

    P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...

  7. 洛谷P5661 公交换乘(CSP-J 2019 T2)

    传送门 题目可能排版有问题,导致出现一些乱码,具体请参考洛谷原题 题目描述 著名旅游城市 B 市为了鼓励大家采用公共交通方式出行,推出了一种地铁换乘公交车的优惠方案: 在搭乘一次地铁后可以获得一张优惠 ...

  8. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  9. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

随机推荐

  1. 【docker】开启remote api访问,并使用TLS加密

    背景: docker默认是能使用本地的socket进行管理,这个在集群中使用的时候很不方便,因为很多功能还是需要链接docker服务进行操作,docker默认也可以开启tcp访问,但是这就相当于把整个 ...

  2. 【shell】判断一个变量是否为空

    #!/bin/bash argv=" if [ -z "$argv" ] then echo "argv is empty" else echo &q ...

  3. A Pangram

    Codeforces Round #295 div2 的A题,题意是判读一个字符串是不是全字母句,也就是这个字符串是否包含了26个字母,无论大小写. Sample test(s) input 12 t ...

  4. Matlab图像处理(03)-基本概念

    概念定义 动态范围:灰度跨跃的值域称为动态范围.上限取决于饱和度,下限取决于噪声. 对比度:一幅图像中最高和最低灰度级间的灰度差. 空间分辨率:图像中可辨别的最小细节的度量.常用度量每单位距离线对数和 ...

  5. 在VS2015中的SDL2.0开发环境搭建

    写本文的目的在于使用网络上的教程及官方的教程(如:http://www.willusher.io/sdl2%20tutorials/2013/08/15/lesson-0-visual-studio) ...

  6. react服务端渲染

    一.服务端渲染的好处 1.SEO, 让搜索引擎更容易读取页面内容: 2.首屏渲染速度更快(重点),无需等待JS文件下载执行过程: 3.更易于维护,服务端和客户端可以共享某些代码: 二.实现原理 服务端 ...

  7. HDU2457 DNA repair —— AC自动机 + DP

    题目链接:https://vjudge.net/problem/HDU-2457 DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory ...

  8. 搭建LoadRunner中的场景(四)控制器的全局设置

    选择“Tools”菜单-“Options”选项打开设置窗口 1.超时设置 2.运行时设置 3.运行时文件存储设置 4.路径翻译表 路径翻译表是一种映射,将控制器上的文件路径转换为远程主机上的文件路径. ...

  9. 2018.3.3 How too much fructose may cause liver damage

    Fructose is the sweetest of the natural sugars. As its name suggests, it is found mainly in fruits. ...

  10. 初入 CLR - 阅读《CLR via C#》笔记

    最近买了一本书<CLR via C#>阅读了第一章 - CLR 的执行模型,对 .NET 一直提到的 CLR 和 .NET Framework 有了一个大致的了解.我理解主要体现在: ■ ...