#include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for (int i=0; i=0; i--) #define pb push_back #define fi first #define se second typedef long long ll; typedef pair pi; vector rnd; int h[2048][170]; int g[170][6][6][11]; void zlepsi(int &a, int b) { a = max(a, b); } void rataj(int pos, int i, int j) { if (pos + 5 + i + j > 165) return; int a[3][6]; int use[3]={5-i, i-j, j}; int generated[3]={5,i,j}; int ptr=pos; REP(x,3) REP(k,generated[x]) a[x][k]=rnd[ptr++]; REP(x,1< bx(x); if (bx.count() == use[0]) REP(y,1< by(y); if (by.count() == use[1]) { vector b; REP(e,5) if (bx[e]) b.push_back(a[0][e]); REP(e,5) if (by[e]) b.push_back(a[1][e]); REP(e,generated[2]) b.push_back(a[2][e]); int pocty[6]; memset(pocty, 0x00, sizeof(pocty)); REP(l,b.size()) pocty[b[l]]++; REP(e,6) zlepsi(g[pos][i][j][e], (e + 1) * pocty[e]); REP(e,6) if (pocty[e] == 3) REP(f,6) if (pocty[f] == 2) zlepsi(g[pos][i][j][7], 3 * (e + 1) + 2 * (f + 1)); REP(e,6) if (pocty[e] == 4) REP(f,6) if (pocty[f] == 1) zlepsi(g[pos][i][j][8], 4 * (e + 1) + 1 * (f + 1)); int poc = 0; REP(e,6) poc += pocty[e] * (e + 1); zlepsi(g[pos][i][j][10], poc); REP(e,6) if (pocty[e] == 5) zlepsi(g[pos][i][j][9], 50); REP(e,2) { bool ok = true; REP(f,5) if (pocty[f + e] != 1) ok = false; if (ok) zlepsi(g[pos][i][j][6], 30); } } } } } int go(int av,int pos) { if(h[av][pos]!=-1) return h[av][pos]; if (av == 0) return 0; int res = 0; REP(i,6) REP(j,i+1) REP(k,11) if (av&(1< v; rnd.clear(); REP(i,300) { v.push_back((A*X+C) % (1LL<<32) ); X=v.back(); rnd.push_back( (X/(1LL<<16))%6); } REP(i,2048) REP(j,170) h[i][j]=-1; memset(g, 0x00, sizeof(g)); REP(j,170) REP(i,6) REP(k,i+1) rataj(j, i, k); printf("%d\n",go((1<<11)-1,0)); } }