记录编号 |
544693 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Rotate Columns |
最终得分 |
100 |
用户昵称 |
ziiidan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.057 s |
提交时间 |
2019-10-23 07:38:10 |
内存使用 |
13.74 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 105;
const int INF = 0x7fffffff;
struct MT {
int val[maxn];
int maxval;
}a[maxn];
int T;
int n, m, ans, maxval;
int c[maxn][maxn];
int read(void)
{
int s = 0, w = 1;
char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1;
for(; ch <= '9' && ch >= '0'; ch = getchar()) s = s * 10 + ch - '0';
return s * w;
}
bool cmp(MT rr, MT tt)
{
return rr.maxval > tt.maxval;
}
void dfs(int pos)
{
if(pos == min(n, m) + 1)
{
int sum = 0;
for(int i = 1; i <= n; i++)
{
int zhx = -INF;
for(int j = 1; j <= min(n, m); j++) zhx = max(zhx, c[i][j]);
sum += zhx;
}
ans = max(ans, sum);
return ;
}
for(int i = 1; i <= n; i++)
{
c[0][pos] = c[n][pos];
for(int j = n; j >= 1; j--) c[j][pos] = c[j - 1][pos];
dfs(pos + 1);
}
}
int main()
{
freopen("happygameT1.in", "r", stdin);
freopen("happygameT1.out", "w", stdout);
T = read();
for(; T; T--)
{
n = read(); m = read();
ans = -INF;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) c[i][j] = read();
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++) a[i].val[j] = c[j][i];
for(int i = 1; i <= m; i++)
{
maxval = -INF;
for(int j = 1; j <= n; j++) maxval = max(maxval, a[i].val[j]);
a[i].maxval = maxval;
}
sort(a + 1, a + m + 1, cmp);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= min(n, m); j++) c[i][j] = a[j].val[i];
dfs(1);
cout << ans << '\n';
}
return 0;
}
/*
40
2 2
5 2
1 5
1 1
3
1 2
1 1
1 2
1 1
1 2
2 3
2 1
1
1
1 1
1
2 1
1
1
1 2
2 3
2 2
1 3
3 3
1 1
1
2 1
3
4
1 1
2
2 2
1 1
1 1
2 2
1 1
1 1
1 1
1
2 1
1
1
2 1
5
3
1 1
2
1 2
2 2
2 1
1
1
2 2
3 2
2 4
1 1
5
1 2
2 1
1 2
1 1
1 2
1 1
1 2
1 1
1 1
3
2 2
1 2
2 2
1 2
4 3
1 1
3
2 1
2
2
1 2
3 2
2 1
3
1
2 1
1
1
2 1
1
2
2 2
2 1
2 1
1 1
2
1 2
3 5
1 1
2
*/
/*
2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
*/
/*
1
4 2
5 4
0 3
3 3
0 3
*/