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. 洪水!(Flooded! ACM/ICPC World Final 1999,UVa815)

    题目描述:竞赛入门经典的习题4-10 解题思路:1.把各个网格想象成一个数组 2.排序 3.雨水总体积去铺满 //太懒了只写了求海拔 #include <stdio.h> #define ...

  2. LeetCode 135——分发糖果

    1. 题目 2. 解答 初始化左序奖赏全为 1,从左往右遍历,如果右边的人评分比左边高,右边奖赏比左边奖赏增 1. 初始化右序奖赏全为 1,从右往左遍历,如果左边的人评分比右边高,左边奖赏比右边奖赏增 ...

  3. Python高级编程-多进程

    要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...

  4. 软件管理——rpm&dpkg、yum&apt-get

    一般来说著名的linux系统基本上分两大类: 1. RedHat系列:Redhat.Centos.Fedora等 2. Debian系列:Debian.Ubuntu等 一.RedHat 系列     ...

  5. 环境变量PATH

    一.举例 我在用户主文件夹执行命令“ls”,会在屏幕显示该文件夹下的所有文件.然而,ls的完整文件名为“/bin/ls”,按道理我不在/bin下要想执行ls命令必须输入“/bin/ls”,但我仅仅需要 ...

  6. Prime Matrix(暴力出奇迹)

    Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...

  7. 2019寒假训练营第三次作业part2 - 实验题

    热身题 服务器正在运转着,也不知道这个技术可不可用,万一服务器被弄崩了,那损失可不小. 所以, 决定在虚拟机上试验一下,不小心弄坏了也没关系.需要在的电脑上装上虚拟机和linux系统 安装虚拟机(可参 ...

  8. 将MathType公式转换为LaTex格式

    LaTex编辑公式不够直观,常常会因为结构复杂导致数据或者符号出错,使用MathType编辑公式后再直接转换成LaTex代码可以避免这个问题. 一.首先在MathType中编辑公式 二.然后点击参数— ...

  9. LintCode-54.转换字符串到整数

    转换字符串到整数 实现atoi这个函数,将一个字符串转换为整数.如果没有合法的整数,返回0.如果整数超出了32位整数的范围,返回INT_MAX(2147483647)如果是正整数,或者INT_MIN( ...

  10. new关键字 、this关键字、base关键字

    使用new,所做的三件事: 1. (类是引用对象,引用对象是在堆中开辟空间)在堆中开辟空间 2. 在开辟的堆空间中创建对象 3. 调用对象的构建函数 4. 隐藏父类成员:子类的成员可以与隐藏从父类继承 ...