当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6766:Diamond Rush

题目描述
There are $n \times n$ cells on a grid, the top-left cell is at $(1,1)$ while the bottom-right cell is at $(n,n)$. In the cell at $(i,j)$, there are $\left(n^2\right)^{a_{i,j}}$ diamonds.

Initially, you are at $(1,1)$, every time you can move to $(i+1,j)$ or $(i,j+1)$ from $(i,j)$ without moving out of the grid. Your destination is at $(n,n)$, so you will take exactly $2n-2$ moves. When you are at a cell, you can take all the diamonds inside this cell, including the starting point $(1,1)$ and the destination $(n,n)$.

However, some cells are blocked but you don't know which cells are blocked. Please write a program to answer $q$ queries. In each query, you will be given four integers $xl,xr,yl,yr$, you need to report the maximum number of diamonds that you can take without passing the cells $(i,j)$ such that $xl\leq i\leq xr$ and $yl\leq j\leq yr$.
输入解释
The first line of the input contains a single integer $T$ ($1 \leq T \leq 5$), the number of test cases.

For each case, the first line of the input contains two integers $n$ and $q$ ($2 \leq n \leq 400,1\leq q\leq 200\,000$), denoting the size of the grid and the number of queries.

Each of the following $n$ lines contains $n$ integers, the $i$-th line contains $a_{i,1},a_{i,2},\dots,a_{i,n}$ ($1\leq a_{i,j}\leq n^2$), denoting the number of diamonds in each cell.

Each of the following $q$ lines contains four integers $xl,xr,yl$ and $yr$ ($1\leq xl\leq xr\leq n,1\leq yl\leq yr\leq n$), denoting each query. It is guaranteed that you can find at least one valid path in each query.
输出解释
For each query, print a single line containing an integer, denoting the maximum number of diamonds that you can take. Note that the answer may be extremely large, so please print it modulo $10^9+7$ instead.
输入样例
1
2 2
2 3
1 4
1 1 2 2
2 2 1 1
输出样例
276
336
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6766

最后修改于 2020-10-25T23:34:12+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000/8000MS(Java/Others) 524288/524288K(Java/Others)