#include #include #include #include using namespace std; typedef long long ll; typedef pair S; int w,h,k; map dp[2]; #define get(s,i) (((s)>>(3*(i)))&7) #define put(s,i,v) ((s)+((v)-get(s,i))*(1<<(3*i))) int connect(int s, int a, int b) { if (a>b) swap(a,b); for (int i=0;ih) swap(w,h); dp[0][S(k,1)]=1; for (int y=0;y::iterator it=dp[idx&1].begin();it!=dp[idx&1].end();++it) { int r=it->first.first; int s=it->first.second; if (y*w+x+r>w*h) continue; ll v=it->second; if (!(y==0&&x==0)&&r>0) { int ns=put(s,x,0); int c0=get(s,x); if (c0==0||exist(ns,c0)) { dp[idx+1&1][S(r-1,normalize(ns))]+=v; } } { int ns=s; int c0=get(s,x); int c1=x-1>=0?get(s,x-1):0; if (c0==0) { if (c1!=0) ns=put(ns,x,c1); else ns=put(ns,x,7); } else { if (c1!=0) ns=connect(ns,c0,c1); } dp[idx+1&1][S(r,normalize(ns))]+=v; } } } } ll ans=0; for (map::iterator it=dp[h*w&1].begin();it!=dp[h*w&1].end();++it) { int r=it->first.first; int s=it->first.second; if (all(s,1)&&get(s,w-1)==1&&r==0) ans+=it->second; } printf("%lld\n",ans); }