Pagini recente » Cod sursa (job #2108598) | Cod sursa (job #2970748) | Cod sursa (job #20707) | Cod sursa (job #377703) | Cod sursa (job #968168)
Cod sursa(job #968168)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define CMAX 1025
#define MOD 666013
int HashValue, SearchValue;
struct nod {
int S;
vector <int> D;
vector <int> Conf;
nod *next;
};
nod *H[MOD + 3];
vector <int> co(5);
vector <int> Dct(3);
vector <int> Zero(3);
bool a[CMAX][CMAX];
void add(int i, int Sum) {
nod *p = new nod;
p->S = Sum;
p->D = Dct;
p->Conf = Zero;
p->next = H[i];
H[i] = p;
}
int c, L, i, j, Csum, n;
int C[CMAX];
int ANS, c1, c2;
struct oite{int v, e1, e2;}Suma[CMAX * CMAX];
int Search_Hash2(int X) {
for (nod *itc = H[X]; itc; itc = itc->next)
if (itc->Conf == co) return 1;
return 0;
}
int Search_Conf() {
co[3] = Dct[1];
co[4] = Dct[2];
sort(co.begin(), co.end());
HashValue = 0;
for (j = 1; j <= 4; ++j)
HashValue = (HashValue * 257 + co[j]) % MOD;
if (!Search_Hash2(HashValue)) {
nod *p = new nod;
p->S = 0;
p->D = Zero;
p->Conf = co;
p->next = H[HashValue];
H[HashValue] = p;
return 0;
}
return 1;
}
void Search_Hash(int X) {
for (nod *it = H[X]; it; it = it->next) {
co[1] = it->D[1];
co[2] = it->D[2];
if (co[1] != Dct[1] && co[1] != Dct[2] && co[2] != Dct[1] && co[2] != Dct[2])
if (!Search_Conf())
++ANS;
}
}
int main() {
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%i%i", &c, &L);
for (i = 1; i <= c; ++i)
scanf("%i", &C[i]);
for (i = 1; i <= c; ++i) {
for (j = 1; j <= c; ++j) {
if (i != j && !a[i][j]) {
Csum = C[i] + C[j];
Suma[++n].v = Csum;
Suma[n].e1 = Dct[1] = i;
Suma[n].e2 = Dct[2] = j;
a[i][j] = a[j][i] = true;
HashValue = Csum % MOD;
add(HashValue, Csum);
}
}
}
for (i = 1; i <= n; ++i) {
SearchValue = L - Suma[i].v;
if (SearchValue < 0) continue;
Dct[1] = Suma[i].e1;
Dct[2] = Suma[i].e2;
HashValue = SearchValue % MOD;
Search_Hash(HashValue);
}
printf("%i\n", ANS);
return 0;
}