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:

8 7 11
4 3 4
6 2 4
2 3 2
5 6 1
2 5 2
1 5 5
2 1 1
3 1 1
7 7 1
7 4 2
8 6 2
输出样例#1:

11
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 5000
int n,m,k,map[maxn][maxn],x,y,dp[maxn][maxn];
int main(){
scanf("%d%d%d",&n,&m,&k);
int x,y,z;
for(int i=;i<=k;i++){
scanf("%d%d%d",&x,&y,&z);
map[x][y]=z;
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dp[i][j]=max(dp[i-][j],dp[i][j-])+map[i][j];
}
}
cout<<dp[n][m];
}

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. MLGBZ

    April cloudy, boss rainy, told me he want to kick But coming so,Formosa Heart sad , Down,down,down W ...

  2. Java I/O模型从BIO到NIO和Reactor模式(转)

    原创文章,转载请务必将下面这段话置于文章开头处(保留超链接).本文转发自技术世界,原文链接 http://www.jasongj.com/java/nio_reactor/ Java I/O模型 同步 ...

  3. LeetCode:矩形区域【223】

    LeetCode:矩形区域[223] 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. 示例: 输入: -3, 0, 3, 4, ...

  4. springcloud 研发规范

    1) 程序结构规范 1: Facade-Stub:包含所有对外提供服务的借口定义,并对外提供 2:  Façade:实现Façade-Stub里面定义的全部借口,可以调用Service模块和Commo ...

  5. CSS3定时提示动画特效

    在线演示 本地下载

  6. Keepalived实现心跳检测实现自动重启

    项目中服务器如果发生宕机:1.故障转移 2.心跳检测 3.负载均衡 4.自动重启 心跳检测: 心跳检测脚本: 写入nginx_check.sh脚本 vi  /etc/keepalived/nginx_ ...

  7. consider increasing the maximum size of the cache.

    虚拟机上搭建jenkins,出现unable to free [10] percent of the cache for Context [/jenkins] 提示让我加大缓存 consider in ...

  8. iOS数据持久化存储之归档NSKeyedArchiver

    归档是一种很常用的文件储存方法,几乎任何类型的对象都能够被归档储存(实际上是一种文件保存的形式),收集了网上的一些资料并结合自己的一些经验,总结如下. 一.使用archiveRootObject进行简 ...

  9. visualVM远程监控JVM

    对于完全没用使用过visualVM的初学者 环境:Windows PC上使用visualVM监控远端JVM @@@@jstatd方式连接@@@@ 1.Windows安装jdk,$JAVA_HOME/b ...

  10. VirtualBox文件系统已满--磁盘扩容

    第1步:为virtualbox虚拟电脑扩容 进入命令行,以Windows系统为例 (特别注意空格和中文) 1.启动CMD命令行,进入VirtualBox的安装目录.如 运行:cmd C:\Users\ ...