-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridGame2.cpp
81 lines (72 loc) · 1.64 KB
/
gridGame2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
//weeeeeeee I am so good so I wrote this script !
using namespace std;
ifstream fin("gridGame.in");
ofstream fout("gridGame.out");
long long total = 0;
int solve(vector< vector<int> > & a, vector<int> & yR, vector<int> & xR, inttotal)
{
++total;
int size = a[0].size(), minCount = 1000000;
bool sth = false;
for (int y = 0; y <= size - 1; ++y)
{
if (yR[y] == 1)
{
continue;
}
for (int x = 0; x <= size - 1; ++x)
{
if (xR[x] == 1)
{
continue;
}
sth = true;
yR[y] = 1;
xR[x] = 1;
minCount = min(minCount, a[y][x] + solve(a, yR, xR));
yR[y] = 0;
xR[x] = 0;
}
}
if (sth == false)
{
return 0;
}
else
{
return minCount;
}
}
int main()
{
int count;
fin >> count;
for (int t = 1; t <= count; ++t)
{
total = 0;
int size;
fin >> size;
vector< vector<int> > a(size, vector<int>(size));
vector<int> yR(size, 0);
vector<int> xR(size, 0);
for (int y = 0; y <= size - 1; ++y)
{
for (int x = 0; x <= size - 1; ++x)
{
fin >> a[y][x];
}
}
fout << solve(a, yR, xR) << " loops : " << total <<'\n';
}
return 0;
}