ZOJ3578(Matrix)

Matrix


Time Limit: 10 Seconds      Memory Limit: 131072 KB

N*M coordinate plane ((0, 0)~(n, m)). Initially the value of all N*M grids are 0.
An operation T(a, b, h, x, y) is defined as follow:
1. Select the maximum value in the matrix (x, y) ~ (x+a, y+b), suppose the maximum value is max
2. Change all the value in the matrix (x, y) ~ (x+a, y+b) into max+h
After C operations, please output the maximum value in the whole N*M coordinate.

Input

The input consists of several cases. 
For each case, the first line consists of three positive integers N , M and C (N ≤ 1000, M ≤ 1000, C ≤ 1000). In the following C lines, each line consists of 5 non-negative number, aibihixiyi (0 ≤ hi ≤ 10000, 0 ≤ xi < n, 0 ≤ yi < m).

Output

For each case, output the maximum height.

Sample Input

3 2 2
2 1 9 1 1
1 1 2 2 1

Sample Output

11

感受:判断两个矩阵是否相交,考虑一定不相交的情况。若考虑相交条件则是有可能相交。并且呀,不相交对立面不一定是相交啊(好人的对立面不一定是坏人啊,有可能是不好不坏的人啦,世界并不是由二元性组成的呀!)

 #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
struct Matrix
{
int x1,x2,y1,y2,maxn;
};
Matrix matrix [+];
bool cover(Matrix a,Matrix b)
{
if(a.x1>=b.x2||b.x1>=a.x2) return false;
if(a.y1>=b.y2||b.y1>=a.y2) return false;
return true;
}
int n,m,c;
int x,y,h,a,b;
int main()
{
while(~scanf("%d%d%d",&n,&m,&c))
{
int ans=; memset(matrix,,sizeof(matrix));
for(int i=;i<c;i++)
{
int temp=;
scanf("%d%d%d%d%d",&a,&b,&h,&x,&y);
matrix[i].x1=x;
matrix[i].x2=x+a;
matrix[i].y1=y;
matrix[i].y2=y+b;
//matrix[i].h=h;
for(int j=;j<i;j++)
{
if(cover(matrix[i],matrix[j]))
temp=max(temp,matrix[j].maxn);
}
matrix[i].maxn=temp+h;
ans=max(ans,matrix[i].maxn);
}
printf("%d\n",ans);
} return ;
} //1 2
//1
//1 5
上一篇:火狐浏览器URL中传中文参数乱码问题


下一篇:swift 学习- 26 -- 泛型