Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbered from 1 to m from left to right. The element in the i-th row and the j-th column is Aij.

Let M({i1i2, ..., is}, {j1j2, ..., jt}) be the matrix that results from deleting row i1i2, ..., is and column j1j2, ..., jt of A and f({i1i2, ..., is}, {j1j2, ..., jt}) be the number of saddle points in matrix M({i1i2, ..., is}, {j1j2, ..., jt}).

Chiaki would like to find all the value of f({i1i2, ..., is}, {j1j2, ..., jt}). As the output may be very large ((2n - 1)(2m - 1) matrix in total), she is only interested in the value

Note that a saddle point of a matrix is an element which is both the only largest element in its column and the only smallest element in its row.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains four integers n and m (1 ≤ nm ≤ 1000) -- the number of rows and the number of columns.

Each of the next n lines contains m integer Ai, 1Ai, 2, ..., Aim (1 ≤ Aij ≤ 106), where Aij is the integer in the i-th row and the j-th column.

It is guaranteed that neither the sum of all n nor the sum of all m exceeds 5000.

<h4< dd="">Output

For each test case, output an integer denoting the answer.

<h4< dd="">Sample Input

2
2 2
1 1
1 1
4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20

<h4< dd="">Sample Output

4
465 这题就是难在读题
我和我队友看了半天这题 觉得这题不能写
后来看题解 知道题意后 这题真的傻逼
题意
一个n*m的矩阵,问n*m个点能否在去掉某些行、列的情况下,成为马鞍点。
马鞍点是行中最小 列中最大的元素(严格大于和小于),问所有 点能够成为马鞍点的方式总数。
然后按每个点算一次贡献就好了
行中最小 就把每一行中比这个值大的数目 每一次有两种状态 选和不选
 列中最大 就把每一行中比这个值小的数目 每一次有两种状态 选和不选
 每个点的贡献就是 expmod(2, cnt1) * expmod(2, cnt2) 

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e3 + ;
int mp[maxn][maxn], L[maxn][maxn], H[maxn][maxn];
int t, n, m;
LL expmod(LL a, LL b) {
LL ret = ;
while(b) {
if (b & ) ret = ret * a % mod;
a = a * a % mod;
b = b >> ;
}
return ret;
}
int main() {
sf(t);
while(t--) {
sff(n, m);
for (int i = ; i < n ; i++) {
for (int j = ; j < m ; j++) {
sf(mp[i][j]);
L[i][j] = mp[i][j];
H[j][i] = mp[i][j];
}
}
for (int i = ; i < n ; i++) sort(L[i], L[i] + m);
for (int i = ; i < m ; i++) sort(H[i], H[i] + n);
LL ans = ;
for (int i = ; i < n ; i++) {
for (int j = ; j < m ; j++) {
int cnt1 = m - (upper_bound(L[i], L[i] + m, mp[i][j]) - L[i]);
int cnt2 = lower_bound(H[j], H[j] + n, mp[i][j]) - H[j];
ans = (ans + expmod(, cnt1) * expmod(, cnt2) % mod) % mod;
}
}
printf("%lld\n", ans);
}
return ;
}

Saddle Point ZOJ - 3955 题意题的更多相关文章

  1. Saddle Point ZOJ - 3955(求每个值得贡献)

    题意: 给出一个矩阵,删掉一些行和列之后 求剩下矩阵的鞍点的总个数 解析: 对于每个点 我们可以求出来 它所在的行和列  有多少比它大的 设为a 有多少比它小的 设为b 然后对于那些行和列 都有两种操 ...

  2. Day7 - C - Saddle Point ZOJ - 3955

    Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbe ...

  3. ZOJ 3955:Saddle Point(思维)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3955 题意:给出一个n*m的矩阵,定义矩阵中的特殊点Aij当且仅当Aij是 ...

  4. ZOJ 3955 Saddle Point 校赛 一道计数题

    ZOJ3955 题意是这样的 给定一个n*m的整数矩阵 n和m均小于1000 对这个矩阵删去任意行和列后剩余一个矩阵为M{x1,x2,,,,xm;y1,y2,,,,,yn}表示删除任意的M行N列 对于 ...

  5. ZOJ 3955 Saddle Point

    排序. 枚举每一个格子,计算这个格子在多少矩阵中是鞍点,只要计算这一行有多少数字比他大,这一列有多少数字比他小,方案数乘一下就是这个格子对答案做出的贡献. #include<bits/stdc+ ...

  6. zoj 3657 策略题 easy

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4880 由于是要去牡丹江.是浙大出题,所以找了份浙大的题,第一道水题做的就不顺 ...

  7. zoj 3647 智商题

    此题就是求格点中三角形的个数. 就是找出三点不共线的个数. n*m的矩形中有(n+1)*(m+1)个格点. 选出三个点的总个数为:C((n+1)*(m+1),3). 减掉共线的情况就是答案了. 首先是 ...

  8. D - Matrix Multiplication ZOJ - 2316 规律题

    Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this grap ...

  9. 九度OJ 1032:ZOJ (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4569 解决:2561 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的 ...

随机推荐

  1. Django学习总结-之-URLS反向解析

    2018-09-15  09:58:49 在CSDN博客审核效率提高之前, 又要在此处向各位唠叨了~ URL 与 URI URL : 统一资源定位符 相当于绝对路径 URI : 统一资源标志符 相当于 ...

  2. 259 [LeetCode] 3Sum Smaller 三数之和较小值

    题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...

  3. Spring Boot - Filter实现简单的Http Basic认证

    Copy自http://blog.csdn.net/sun_t89/article/details/51916834 @SpringBootApplicationpublic class Spring ...

  4. httpd 2.2.15 添加流媒体模块

    项目中使用的一直都是 httpd  2.2.15  用于播放视频资源,近期有个新产品上线发现快进视频会出现卡顿情况,因此添加了流媒体模块.(怀疑是新产品中的播放器进行了更改) 原文:http://li ...

  5. 软件工程第四周作业之四则运算-C#实现

    拿到题目的时候,快放假了,也没心思做.十月七号的一下午大概从两点做到八点半,加上十月八号的十二点半到两点半,做了一共八个半小时,去掉吃饭半个小时那么一共做了八个小时. 逆波兰表达式我是扒的别人代码,没 ...

  6. POJ 1995 (快速幂)

    这道题普通做法会发生溢出且会超时,应当用快速幂来求解. 快速幂讲解 #include <cstdio> #include <cmath> using namespace std ...

  7. <Effective C++>读书摘要--Implementations<一>

    1.For the most part, coming up with appropriate definitions for your classes (and class templates) a ...

  8. Jenkins系列-Jenkins初始化配置

    初始化 访问,如:127.0.0.1:8088/Jenkins 第一次要求输入密码,初始密码在文件中查看. 执行以下命令查看 $ cat ${USER_HOME}\.jenkins\secrets\i ...

  9. win7系统日志分支删除方法

    这篇日志有问题,自己亲身尝试失败,这里只提供思路,谢谢(改天突破再做修改) 之前电脑装过德国的叫啥子软件来着,当时在系统自动创建了日志,后来软件卸载了,发现还是有这个日志主键,(我有强迫症)心里不爽, ...

  10. QT分析之消息事件机制

    原文地址:http://blog.163.com/net_worm/blog/static/127702419201001432028526/ 上回我们分析到QPushButton的初始化,知道了Wi ...