求大佬改进:H题——本题主要考察了DFS
我思路是对的,但一直超时。想来想去也不知道怎么减少时间复杂度。。。
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
int t,n, x,y;
int b[20];
char a[400][4];
cin >> t;
int t1 = t;
while (t)
{
cin >> n;
x = 0;
y = 0;
b[t1 - t] = 0;
for (int i = 1; i < n * n; i++)
for (int j = 1; j <= 4; j++)
{
cin >> a[i][j];
if (a[i][j] == '1')
x++;
if (a[i][j] == '2')
x--;
}
b[t1-t]= 10 + x;
t--;
}
for (int i=0;i<t1;i++)
{
cout << b[i];
}
return 0;
}