Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <bits/stdc++.h>
using namespace std;
#define R(i,e)for(I i=1;i<min(20,e);++i)
#define X(x) if(x<1||V[x])continue;V[x]=x;
#define J(a,b,c) X(a)X(b)X(c)
#define P printf
#define D "%2d "
typedef int I;I T=38;I main() {
I V[T];
R(h,20)R(c,20)R(s,20)
R(a,T-max(c,h))if(a!=h&a!=c&a!=s)
R(l,T-max(c,s))if(l!=h&l!=c&l!=s&l!=a)
R(q,T-max(h,s))if(q!=h&q!=c&q!=s&q!=a&q!=l) {
I d=T-a-h,b=T-a-c,g=T-c-l,p=T-l-s,r=T-q-s,m=T-h-q;
R(e,T-max(g+d,b+m)) {
I f=T-g-e-d,i=T-b-e-m,n=T-d-i-r,o=T-p-n-m,k=T-g-o-r,j=T-h-i-k-l;
memset(V,0,sizeof V);
J(a,b,c)J(d,e,f)J(g,h,i)J(j,k,l)J(m,n,o)J(p,q,r)X(s)
P(" " D D D "\n",a,b,c);
P(" " D D D D"\n",d,e,f,g);
P(D D D D D"\n",h,i,j,k,l);
P(" " D D D D"\n",m,n,o,p);
P(" " D D D"\n",q,r,s);
cout << "=============" << endl;
return 0; // uncomment to print only the one unique solution
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.