全部試す。
class TheBasketballDivOne {
public:
int find(int n, int m)
{
set<string> wseq;
int game = n * n - n;
bool g[n][n];
for (int bit = 0; bit < (1 << game); ++bit) {
int b = bit;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) continue;
g[i][j] = b % 2;
b /= 2;
}
}
string s;
for (int i = 0; i < n; ++i) {
int w = 0;
for (int j = 0; j < n; ++j) {
if (i == j) continue;
w += g[i][j] == true;
w += g[j][i] == false;
}
s += 'A' + w;
}
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
wseq.insert(s);
}
int ret = 0;
FOR (i, wseq) {
if((*i)[0] == 'A' + m) ++ret;
}
return ret;
}
};
0 件のコメント :
コメントを投稿