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)

最新文章

  1. 简单的VC++ ADO帮助类
  2. 表单验证神器——jquery.validate插件
  3. 进度条,随机数---demo笔记【原创】
  4. 构建高效安全的Nginx Web服务器
  5. C++ 嵌套类使用(二)
  6. getJSON回调函数不执行问题?
  7. table头部、尾部固定;中间内容定高自适应滚动
  8. 2014最新SSH框架面试题大收集
  9. iphone在iframe页面的宽度不受父页面影响,避免撑开页面
  10. TLD算法原理--学习理解之(二)
  11. input依次输入密码
  12. window bat 切换目录并执行php文件
  13. python 三
  14. HashMap底层实现原理(JDK1.8)源码分析
  15. 分布式事务之TCC服务设计和实现注意事项
  16. LeetCode--496--下一个更大元素I(java)
  17. Unable to compile class for JSP
  18. Java程序员进击书籍推荐
  19. js 正则表达式校验必须包含字母、数字、特殊字符
  20. part1:12-sudo用户管理和Linux密码故障排除

热门文章

  1. Oracle数据库基础--存储过程和函数
  2. java.lang.UnsupportedClassVersionError: com/dw/Function : Unsupported major.minor version 52.0
  3. 3D文字特效
  4. EntityFramework codefirst
  5. win10系统使用clover时程序崩溃的解决
  6. 1--单独使用jdbc开发问题总结
  7. 标准兼容HTML5输入框提示信息的插件iHolder_v0.1.06.21.2014_预览版
  8. 存储过程之rowtype 使用
  9. Struts2与ServletAPI解耦
  10. PS 滤镜— —球面化效果