洛谷P3431 [POI2005]AUT-The Bus
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≤109, 1\le m\le 10^91≤m≤109, 1\le k\le 10^51≤k≤105).
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_ixi, y_iyi and p_ipi, separated by single spaces, 1\le x_i\le n1≤xi≤n,1\le y_i\le m1≤yi≤m,1\le p_i\le 10^61≤pi≤106 . A triplet of this form signifies that by the intersection(x_i,y_i)p_i(xi,yi)pi 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.
输入输出样例
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
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的更多相关文章
- 树状数组 二维偏序【洛谷P3431】 [POI2005]AUT-The Bus
P3431 [POI2005]AUT-The Bus Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 ...
- 洛谷 P3431:[POI2005]AUT-The Bus(离散化+DP+树状数组)
题目描述 The streets of Byte City form a regular, chessboardlike network - they are either north-south o ...
- 洛谷 P3420 [POI2005]SKA-Piggy Banks
P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...
- 洛谷 P3419 [POI2005]SAM-Toy Cars
P3419 [POI2005]SAM-Toy Cars 题目描述 Johnny is a little boy - he is only three years old and enjoys play ...
- 洛谷 P3420 [POI2005]SKA-Piggy Banks 题解
蒟蒻的第二篇题解 嗯,直接进入正题 先告诉你们这是并查集,好吧,标签上面有,再来分析这为什么是并查集. 根据题意: 每一个存钱罐能够用相应的钥匙打开或者被砸开,Byteazar已经将钥匙放入到一些存钱 ...
- 【模板】矩阵快速幂 洛谷P2233 [HNOI2002]公交车路线
P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...
- 洛谷P5661 公交换乘(CSP-J 2019 T2)
传送门 题目可能排版有问题,导致出现一些乱码,具体请参考洛谷原题 题目描述 著名旅游城市 B 市为了鼓励大家采用公共交通方式出行,推出了一种地铁换乘公交车的优惠方案: 在搭乘一次地铁后可以获得一张优惠 ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
随机推荐
- SAP RFC 的介绍
第一部分 RFC技术 什么是RFC? RFC是SAP系统和其他(SAP或非SAP)系统间的一个重要而常用的双向接口技术,也被视为SAP与外部通信的基本协议.简单地说,RFC过程就是系统调用当前系统外的 ...
- Java for LeetCode 128 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- WebsiteCrawler
看到网上不少py的爬虫功能极强大,可惜对py了解的不多,以前尝试过使用c# WebHttpRequert类来读取网站的html页面源码,然后通过正则表达式筛选出想要的结果,但现在的网站中,多数使用js ...
- LightOJ - 1284 Lights inside 3D Grid —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid PDF (English) Statistic ...
- jQuery(expression, [context])
jQuery(expression, [context]) 返回值:jQuery 概述 这个函数接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQuery 的 ...
- Hadoop- 流量汇总程序之如何实现hadoop的序列化接口及代码实现
流量汇总程序需求 统计每一个用户(手机号)锁耗费的总上行流量.下行流量.总流量. 流程剖析 阶段:map 读取一行数据,切分字段, 抽取手机号,上行流量,下行流量 context.write(手机号, ...
- RQNOJ 169 最小乘车费用:水dp
题目链接:https://www.rqnoj.cn/problem/169 题意: 给出行驶1-10公里的费用(所有车一样),可以倒车,问行驶n公里的最小费用. 题解: 大水题... (=´ω`=) ...
- 自动拆装箱(int,Integer)
包装类型Java语言是一个面向对象的语言,但是Java中的基本数据类型却是不面向对象的,这在实际使用时存在很多的不便,为了解决这个不足,在设计类时为每个基本数据类型设计了一个对应的类进行代表,这样八个 ...
- Oracle获取日期的特定部分
(1)oracle中extract()函数从oracle 9i中引入,用于从一个date或者interval类型中截取到特定的部分 ,语法:extract ({ year | month | day ...
- java基础知识 学习 关于URL中传递的参数含有特殊字符
有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了.下表中列出了一些URL特殊符号及编码 ...