是暴力
并没有预处理
会影响到结果吗?
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+10,M = 110,inf = 0x3f3f3f3f;
template <class T> void read(T &w){
w=0;int f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){(w*=10)+=ch-'0';ch=getchar();}
w*=f;
}
template <class T> void write(T w){
if(w<0){putchar('-');w*=-1;}
if(w/10) write(w/10);
putchar(w%10+'0');
}
int n,k;
int f[13][1 << 13][99];
int g[N];
int sum;
void work(int S)
{
int res = 0;
int x = S;
while(S)
{
if(S & 1)res ++;
S >>= 1;
}
g[x] = res;
}
bool check(int S)
{
if(((S & (S << 1) )!= 0 && (S & (S >> 1) )!= 0 ) )return false;
else return true;
}
signed main()
{
read(n), read(k);
for(int s = 0; s <= (1 << n) - 1; s ++)work(s);//预处理
for(int S = 0; S <= (1 << n) - 1; S ++)
{
if(check(S))
{
f[1][S][g[S]] = 1;
}
}
for(int i = 2; i <= n; i ++)
{
for(int S = 0; S <= (1 << n) - 1; S ++)
{
if(check(S))
{
for(int K = 0; K <= (1 << n) - 1; K ++)
{
if(K & S == 0 && (K & (S << 1)) == 0 && ((K << 1) & S) == 0 && check(K))
{
for(int num = g[S]; num <= k; num ++)
{
f[i][S][num] += f[i - 1][K][num - g[S]];
}
}
}
}
}
}
sum = 0;
for(int S = 0; S <= (1 << n) - 1; S ++)
{
sum += f[n][S][k];
}
//ans = f[n][~][k];
write(sum);
return 0;
}