SGU 168 Matrix (DP)
来源:互联网 发布:php redis缓存周期 编辑:程序博客网 时间:2024/05/09 09:06
原题:
168. Matrix
time limit per test: 0.5 sec.
memory limit per test: 16000 KB
memory limit per test: 16000 KB
input: standard
output: standard
output: standard
You are given N*M matrix A. You are to find such matrix B, that B[i,j]=min{ A[x,y] : (y>=j) and (x>=i+j-y) }
Input
On the first line of the input there are two integer numbers, N and M (1<=N,M<=1000). Then matrix A follows: next N lines contains M integers each (not greater than 32000 by absolute value). The j-th number on then i-th of this lines is A[i,j].
Output
Write matrix B in the same format as matrix A, but without N and M.
Sample test(s)
Input
3 3 1 2 3 4 5 6 7 8 9
Output
1 2 3
2 3 6
3 6 9
2 3 6
3 6 9
[submit]
[forum]
Date:
#include <iostream>#include <iomanip>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <deque>#include <string>#include <cmath>#include <stack>#include <vector>#include <utility>#include <set>#include <map>#include <sstream>#include <climits>#pragma comment(linker, "/STACK:1024000000,1024000000")#define pi acos(-1.0)#define INF 2147483647using namespace std;typedef long long ll;typedef pair <int,int > PP;int N[1005][1005],M[1005][1005],s[1005][1005];int main(){ int n,m; scanf("%d%d",&n,&m); int min_=32005; for(int i=0; i<n; i++) for(int j=0; j<m; j++) scanf("%d",&N[i][j]); for(int j=m-1; j>=0; j--) { int min__=32005; for(int i=n-1; i>=0; i--) { min_=min(min_,N[i][j]); min__=min(min__,N[i][j]); s[i][j]=min__; } M[0][j]=min_; } for(int i=1; i<n; i++) for(int j=0; j<m; j++) { min_=s[i][j]; if(j<m-1) { min_=min(min_,M[i-1][j+1]); } M[i][j]=min_; } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { j==0?printf("%d",M[i][j]):printf(" %d",M[i][j]); } printf("\n"); }}
Server time: 2017-11-02 12:37:05Online Contester Team © 2002 - 2016. All rights reserved.
阅读全文
1 0
- SGU 168 Matrix (DP)
- SGU 168 Matrix DP
- sgu 168 Matrix DP
- sgu 168 Matrix
- SGU - 196 - Matrix Multiplication (矩阵乘法)
- sgu 249 Matrix
- sgu 196 Matrix Multiplication
- SGU 249 Matrix
- sgu 196 Matrix Multiplication
- sgu-249 Matrix
- HDU5569 matrix(dp)
- matrix (dp)
- SGU 201 Non Absorbing DFA (DP)
- sgu - 269 - Rooks(大数dp)
- sgu - 518 - Kidnapping(set + dp)
- SGU 131 Hardwood floor(状压DP)
- SGU 390 Tickets(数位DP)
- SGU 134 Centroid(树形DP)
- 查看、修改mysql的用户名和密码
- PCA: Principal Components Analysis,主成分分析法原理
- 错误 'ASP 0175 : 80004005'
- HDU 3853 LOOPS
- 戏剧 taobao
- SGU 168 Matrix (DP)
- Windows下react环境的配置与项目的新建
- 了解Java线程的start方法如何回调run方法
- 1.使用栈获取最小值
- Java解析XML的几种方法
- 划分树(数第几大)
- NewStart(二)—— LoadUIResource
- SDUT 3342 数据结构实验之二叉树三:统计叶子数
- JQuery动画一些操作