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

建议使用的浏览器:

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

5825:permu

题目描述
ZZX has a sequence a[1..n], which is a permutation of 1,2,...,n.

Now ZZX wants to perform some modifications on this sequence: every time he can choose a pair of integers i,j, satisfying 1<=i<j<=n and a[i]>a[j], then swap a[i] and a[j].

If a permutation b[1..n] can be obtained by performing some modifications (possibly nothing is performed) on the initial sequence a, then ZZX says b is reachable from a.

Now JRY has m sequences a_1[1..n], a_2[1..n], ..., a_m[1..n]. Each of them is a permutation of 1,2,...,n. He wants to know how many pairs of (i,j) (1<=i<=m,1<=j<=m) satisfy a_i is reachable from a_j.
输入解释
First line contains an integer t. Then t testcases follow.

In each testcase: First line contains two integers n and m. Next m lines, each contains n integers a_i[1],a_i[2],...,a_i[n].

a_i is a permutation of 1,2,...,n.

There are at most 1000 small testcases and 1 big testcase. Small testcases satisfy 1<=n<=5 and 1<=m<=500. Big testcase satisfies 1<=n<=9, 1<=m<=300000.
输出解释
For each testcase print one integer as your answer in a line.
输入样例
2
3 3
1 2 3
3 1 2
2 3 1
2 2
1 2
1 2
输出样例
5
4
来自杭电HDUOJ的附加信息
Author 学军中学
Recommend wange2014

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

源链接: HDU-5825

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

共提交 0

通过率 --%
时间上限 内存上限
7000/3500MS(Java/Others) 262144/262144K(Java/Others)