- //先考虑一下一维的情况,就不难解决了
- //2008-09-20 10:46:52 Accepted 2975 C++ 450 260
- #include<stdio.h>
- char fuwa[5] = {'B', 'J', 'H', 'Y', 'N'};
- int solve(int m, int n)
- {
- char matrix[251][251];
- int res = 0;
- for(int i = 0; i < m; i++)
- scanf("%s", matrix[i]);
- for(int i = 0; i < m; i++)
- for(int j = i + 1; j < m; j++)
- for(int k = 0; k < 5; k++)
- {
- int len = 0;
- for(int x = 0; x < n; x++)
- if(matrix[i][x] == fuwa[k] && matrix[j][x] == fuwa[k])
- len++;
- if(len > 0) res += len * (len - 1) / 2;//c(2, len)
- }
- return res;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("2975.txt", "r", stdin);
- #endif
- int t, m, n;
- scanf("%d", &t);
- while(t--)
- {
- scanf("%d%d", &m, &n);
- printf("%d/n", solve(m, n));
- }
- #ifndef ONLINE_JUDGE
- fclose(stdin);
- #endif
- return 0;
- }
problem 2975
最新推荐文章于 2020-12-03 16:14:56 发布