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 numbered from 1 to m from left to right. The element in the i-th row and the j-th column is Ai, j.
Let M({i1, i2, ..., is}, {j1, j2, ..., jt}) be the matrix that results from deleting row i1, i2, ..., is and column j1, j2, ..., jt of A and f({i1, i2, ..., is}, {j1, j2, ..., jt}) be the number of saddle points in matrix M({i1, i2, ..., is}, {j1, j2, ..., jt}).
Chiaki would like to find all the value of f({i1, i2, ..., is}, {j1, j2, ..., 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 ≤ n, m ≤ 1000) -- the number of rows and the number of columns.
Each of the next n lines contains m integer Ai, 1, Ai, 2, ..., Ai, m (1 ≤ Ai, j ≤ 106), where Ai, j 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.
Output
For each test case, output an integer denoting the answer.
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
Sample Output
4
465 思路:saddle点的定义是行最小,列最大,那么我们就统计每一个点对saddle点的贡献,即这些点是saddle点的时候,去掉当前行比他大的列与当前列比他小的行对该点的贡献无影响,即是组合数从0到x,就是2^x,列同理,就是2^(x+y),快速幂+二分查找即可
typedef long long LL; const int MOD = 1e9+;
const int maxm = ; int A[maxm][maxm], R[maxm][maxm], C[maxm][maxm]; LL quick_pow(LL a, LL b) {
LL ret = ;
while(b) {
if(b & ) ret = (ret * a) % MOD;
a = (a * a) % MOD;
b >>= ;
}
return ret;
} int main() {
int T, n, m;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j) {
scanf("%d", &A[i][j]);
R[i][j] = C[j][i] = A[i][j];
}
for(int i = ; i <= n; ++i)
sort(R[i]+, R[i]+m+);
for(int i = ; i <= m; ++i)
sort(C[i]+, C[i]++n); LL ans = ;
int row, col;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
row = m-(upper_bound(R[i]+, R[i]++m, A[i][j]) - R[i] - ); // larger than A[i][j] in row
col = lower_bound(C[j]+, C[j]++n, A[i][j]) - C[j] - ; // lower than A[i][j] in column
ans = (ans+quick_pow(, col+row))%MOD;
}
}
printf("%lld\n", ans);
}
return ;
}
Day7 - C - Saddle Point ZOJ - 3955的更多相关文章
- 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 ...
- Saddle Point ZOJ - 3955(求每个值得贡献)
题意: 给出一个矩阵,删掉一些行和列之后 求剩下矩阵的鞍点的总个数 解析: 对于每个点 我们可以求出来 它所在的行和列 有多少比它大的 设为a 有多少比它小的 设为b 然后对于那些行和列 都有两种操 ...
- ZOJ 3955:Saddle Point(思维)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3955 题意:给出一个n*m的矩阵,定义矩阵中的特殊点Aij当且仅当Aij是 ...
- ZOJ 3955 Saddle Point
排序. 枚举每一个格子,计算这个格子在多少矩阵中是鞍点,只要计算这一行有多少数字比他大,这一列有多少数字比他小,方案数乘一下就是这个格子对答案做出的贡献. #include<bits/stdc+ ...
- ZOJ 3955 Saddle Point 校赛 一道计数题
ZOJ3955 题意是这样的 给定一个n*m的整数矩阵 n和m均小于1000 对这个矩阵删去任意行和列后剩余一个矩阵为M{x1,x2,,,,xm;y1,y2,,,,,yn}表示删除任意的M行N列 对于 ...
- ZOJ Saddle Point 数学思维题
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564 根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- day7
本节作业: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...
随机推荐
- PAT T1015 Letter-moving Gam
双下标法找最长公共子序列(不能删除字符) #include<bits/stdc++.h> using namespace std; ; string s; string t; int ma ...
- 汇编语言从入门到精通-5微机CPU的指令系统1
微机CPU的指令系统 5.1 汇编语言指令格式 为了介绍指令系统中指令的功能,先要清楚汇编语言是如何书写指令的,这就象在学习高级语言程序设计时,要清楚高级语言语句的语义.语法及其相关规定一样. 5.1 ...
- Xcode 8 修改已创建工程的 organizion name
在创建工程时,会需要填写公司信息,对于已创建的工程,新建文件时,公司信息显示为刚开始创建的公司信息.如果需要对公司名称进行修改,需进行以下 可以 打开 工程名.xcodeproj 文件 (显示包内容) ...
- Array数组的方法总结
1.检测数组 自从ECMAScript3作出规定后,就出现了确定某个对象是不是数组的经典问题.对于一个网页,或者一个全局作用域而言,使用instanceof操作符就能得到满意结果. if (value ...
- Windows密码安全性测试
一.本地管理员密码如何直接提取 1.1直接通过mimikatz读取管理员密码 (不能交互式,不能在webshell下用,图形化界面很好用) 第一条:privilege::debug ...
- Django 学习组件分页器与自定制分页器
一.Django 分页器 1.django的分页器基础版 (1)首先是基础数据分别为 from django.db import models # Create your models here. c ...
- 笔记||Python3进阶之读取和写入yaml配置文件
yaml是专门用来写配置文件的语言,简洁强大,远比JSON格式方便,yaml在python语言中有PyYAML安装包. - 首先需要pip安装:pip install pyyaml - yaml基本语 ...
- java并发:初探sleep方法
sleep与wait sleep是Thread方法,使得当前线程从运行态变为阻塞态.但它不会释放对象的锁. wait方法是Object方法,它的作用是使得当前拥有对象锁的线程从运行态变为阻塞态, 它会 ...
- 四、spring集成ibatis进行项目中dao层基类封装
Apache iBatis(现已迁至Google Code下发展,更名为MyBatis)是当前IT项目中使用很广泛的一个半自动ORM框架,区别于Hibernate之类的全自动框架,iBatis对数据库 ...
- JDBC和连接池
JDBC 所有的数据库操作框架都是用在JDBC的基础上做多次封装的,因为JDBC的操作很复杂 引入Jar包 连接数据库操作 书写sql语句,传参 查询,取值 关闭连接 //1.注册驱动(静态方法)(包 ...