1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N = 2010;
int sta[N], tot_line[N]; int cnt = 0; int n, king; ll f[10][N][110];
void dfs(int status, int sum, int pos) { if(pos >= n) { sta[++cnt] = status; tot_line[cnt] = sum; return; } dfs(status, sum, pos + 1); dfs(status+(1<<pos), sum+1, pos+2); }
int main() { scanf("%d%d", &n, &king); dfs(0, 0, 0); for(int i = 1; i <= cnt; i++) { f[1][i][tot_line[i]] = 1; } for(int i = 2; i <= n; i++) { for(int j = 1; j <= cnt; j++) { for(int k = 1; k <= cnt; k++) { if(sta[j] & sta[k]) continue; if((sta[j]<<1) & sta[k]) continue; if(sta[j] & (sta[k]<<1)) continue; for(int s = king; s >= tot_line[j]; s--) { f[i][j][s] += f[i-1][k][s-tot_line[j]]; } } } } ll ans = 0; for(int i = 1; i <= cnt; i++) { ans += f[n][i][king]; } printf("%lld\n", ans);
return 0; }
|