https://i2.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-424-Div-1-rated-based-on-VK-Cup-Finals-problem-D-Singer-House-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals), problem: (D) Singer House Solution In C/C++

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const LL Maxn = 410;
const LL Mod = 1e9+7;
LL f[Maxn][Maxn], n;
void add(LL &x, LL y) { x = (x+y)%Mod; }
int main() {
LL i, j, k;
scanf(“%I64d”, &n);
f[n][0] = f[n][1] = 1;
for(i = n-1; i >= 1; i–){
for(j = 0; j <= i; j++){
for(k = 0; k <= j; k++){
add(f[i][j], f[i+1][k]*f[i+1][j-k]%Mod*(j*2+1)%Mod);
if(k != j) add(f[i][j], f[i+1][k]*f[i+1][j-1-k]%Mod);
add(f[i][j], f[i+1][k]*f[i+1][j+1-k]%Mod*k*(j+1-k)*2%Mod);
}
for(k = 2; k <= j+1; k++) add(f[i][j], f[i+1][k]*f[i+1][j+1-k]%Mod*k*(k-1)*2%Mod);
}
}
printf(“%I64d\n”, f[1][1]);
return 0;
}

(Visited 27 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: