constint N=12,K=N*N,S=(1<<N); longlong f[N][K][S]; bool st[S]; int num[S];
boolcheck(int s) { for (int bit=0;bit<12;++bit) if ((s>>bit&1)&(s>>bit+1&1)) returnfalse; returntrue; }
intmain() { int n,k;scanf("%d %d",&n,&k); for (int s=0;s<(1<<n)-1;++s) { st[s]=check(s); if (st[s]) { int tmp=s; while (tmp) { num[s]++; tmp-=(tmp&-tmp); } } } f[0][0][0]=1; for (int i=1;i<=n;++i) for (int s=0;s<(1<<n)-1;++s) { if (!st[s]) continue; for (int ls=0;ls<(1<<n)-1;++ls) if (st[ls]&&!(s&(ls<<1))&&!(s&ls)&&!((s<<1)&ls)) { for (int j=num[s];j<=k;++j) f[i][j][s]+=f[i-1][j-num[s]][ls]; } } longlong res=0; for (int s=0;s<(1<<n)-1;++s) res+=f[n][k][s]; printf("%lld\n",res); return0; }
boolvalid(int l,int s) { for (int i=1;i<=m;++i) if ((!a[l][i])&(s>>i-1&1)) returnfalse; for (int i=0;i<m-1;++i) if ((s>>i&1)&(s>>i+1&1)) returnfalse; returntrue; }
intmain() { scanf("%d %d",&n,&m); for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) scanf("%d",&a[i][j]); f[0][0]=1; for (int i=1;i<=n;++i) for (int s=0;s<(1<<m);++s) { if (!valid(i,s)) continue; for (int ls=0;ls<(1<<m);++ls) if (valid(i-1,ls)&&!(s&ls)) f[i][s]+=f[i-1][ls]; } ll res=0; for (int s=0;s<(1<<m);++s) res=(res+f[n][s])%Mod; cout<<res<<endl; return0; }
constint N=101,S=1<<10; vector<int> st; int f[2][S][S]; int v[N],n,m; int cnt[S];
boolvalid(int s) { for (int i=0;i<m;++i) if ((s>>i&1)+(s>>i+1&1)+(s>>i+2&1)>=2) returnfalse; returntrue; }
intnum(int s) { int res=0; while (s) { res++; s-=(s&-s); } return res; }
intmain() { scanf("%d %d",&n,&m); for (int i=1;i<=n;++i) { char op[14]; scanf("%s",op); for (int j=0;j<m;++j) v[i]|=(op[j]!='P')<<j; } for (int s=0;s<(1<<m);++s) if (valid(s)) { st.push_back(s); cnt[st.size()-1]=num(s); } for (int i=1;i<=n;++i) for (int i0=0;i0<st.size();++i0) for (int i1=0;i1<st.size();++i1) { int &s0=st[i0],&s1=st[i1]; if ((s0&v[i])|(s1&v[i-1])|(s0&s1)) continue; for (int i2=0;i2<st.size();++i2) { int &s2=st[i2]; if ((s2&v[i-2])|(s0&s2)|(s1&s2)) continue; f[i&1][i0][i1]=max(f[i-1&1][i1][i2]+cnt[i0],f[i&1][i0][i1]); } } int res=0; for (int i=0;i<st.size();++i) for (int j=0;j<st.size();++j) res=max(res,f[n&1][i][j]); cout<<res<<endl; return0; }