Skip to content

Instantly share code, notes, and snippets.

@kusano
Last active March 19, 2016 18:12
Show Gist options
  • Save kusano/2a92c9923e3281d47eb6 to your computer and use it in GitHub Desktop.
Save kusano/2a92c9923e3281d47eb6 to your computer and use it in GitHub Desktop.
#include <vector>
#include <algorithm>
using namespace std;
class MultiplicationTable2{public:
int minimalGoodSet( vector <int> table )
{
int n = 0;
while (n*n < int(table.size()))
n++;
int ans = n;
for (int i=0; i<n; i++)
{
vector<bool> S(n);
S[i] = true;
for (int j=0; j<n; j++)
for (int k=0; k<n; k++)
for (int l=0; l<n; l++)
if (S[k] && S[l])
S[table[k*n+l]] = true;
int c = 0;
for (int i=0; i<n; i++)
if (S[i])
c++;
ans = min(ans, c);
}
return ans;
}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment