首页 > 其他分享 >Codeforces Round 424 (Div. 1)D. Singer House

Codeforces Round 424 (Div. 1)D. Singer House

时间:2023-08-04 11:35:45浏览次数:41  
标签:Singer cdot House ll Codeforces long define include mod

传送门

显然要自底向上进行\(dp\)

深度相同的子树结构相同所以可以利用深度来代表子树。

那么就应该统计出有向路径的个数。

考虑路径由链所拼成。那么状态里应该有有向链的条数。

设\(f_{i,j}\)表示深度为\(i\)链条数为\(j\)的方案数。

不选当前的节点则\(f_{i,j}=f_{i+1,k}\cdot f_{i+1,j-k}\)

若当前节点自成一链则\(f_{i,j}=f_{i+1,k}\cdot f_{i+1,j-k-1}\)

若当前节点和其他链构成一链\(f_{i,j}=f_{i+1,k}\cdot f_{i+1,j-k}\cdot 2j\)

通过当前节点连接两条链\(f_{i,j-1}=f_{i+1,k}\cdot f_{i+1,j-k}\cdot j\cdot (j-1)\)

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define putl_(x) printf("%lld ",x);
#define get(x) x=read()
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(int i=p;i<=n;i+=1)
#define fep(n,p,i) for(int i=n;i>=p;--i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define pii pair<int,int>
#define mk make_pair
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define sq sqrt
#define x(w) t[w].x
#define r(w) t[w].r
#define id(w) t[w].id
#define R(w) s[w].r
#define yy p<<1|1
#define zz p<<1
#define sum(w) t[w].sum
#define mod 1000000007
#define sc(A) scanf("%d",&A)
#define scs(A) scanf("%s",A);
#define put(A) printf("%d\n",A)
#define min(x,y) (x>=y?y:x)
#define max(x,y) (x>=y?x:y)
#define sub(x,y) (x-y<0?x-y+mod:x-y)
#define EPS 1e-7
using namespace std;
const int MAXN=410,G=(mod+1)>>1;
int n,m;
int f[MAXN][MAXN];
signed main()
{
	//freopen("1.in","r",stdin);
	sc(n);
	f[n][0]=f[n][1]=1;
	fep(n-1,1,i)
	{
		rep(0,i+1,j)
		{
			rep(0,j,k)
			{
				f[i][j]=(f[i][j]+(ll)f[i+1][k]*f[i+1][j-k])%mod;
				if(j>k)f[i][j]=(f[i][j]+(ll)f[i+1][k]*f[i+1][j-k-1])%mod;
				f[i][j]=(f[i][j]+(ll)f[i+1][k]*f[i+1][j-k]%mod*2*j)%mod;
				if(j>=1)f[i][j-1]=(f[i][j-1]+(ll)f[i+1][k]*f[i+1][j-k]%mod*j%mod*(j-1))%mod;
			}
		}
	}
	put(f[1][1]);
	return 0;
}

标签:Singer,cdot,House,ll,Codeforces,long,define,include,mod
From: https://www.cnblogs.com/chdy/p/17605415.html

相关文章

  • Codeforces 1855B:Longest Divisors Interval 最长的连续约数区间
    1855B.LongestDivisorsIntervalDescription:对于一个整数\(n\)\((1\leqn\leq10^{18})\),找到一段最长的区间\([l,r]\),使得区间内所有数均为\(n\)的约数。Analysis:如果\(n\)是一个奇数(非\(2\)的倍数),由于\(odd=odd\timesodd\),则不可能有连续的两个整数均为......
  • Codeforces Round 449 (Div. 1) D. Nephren Runs a Cinema 卡特兰数
    luogu链接题意不再赘述。优先枚举的应该是\(VIP\)用户,枚举范围应该是\([0,n-l]\)之后总客户数为\(s=n-i\)再考虑枚举\(100\)的总人数为\(x\)则要求\(s-2x\in[l,r]\)这部分方案数应该为从\((0,0)\)到达\((s-x,x)\)且不越过\(y=x\)的方案数。利用折线法求出方案数为\(C(s,x)......
  • Educational Codeforces Round 38 C- F
    EducationalCodeforcesRound38C-Fhttps://codeforces.com/contest/938今天写出了三题ovoC.ConstructingTests多画几个图就能发现,对于\(n\timesn\)的正方形来说,要使得\(m\timesm\)的子正方形至少有一个\(0\),则最少的\(0\)个数为\(\lfloor\frac{n}{m}\rfloo......
  • Educational Codeforces Round 104
    https://codeforces.com/contest/1487A.Arena统计与最小值不同的数字数量。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintM=(1<<15)-1;voidsolve(){intn;cin>>n;vector<int>a(n);for(......
  • Educational Codeforces Round 88
    A.BerlandPoker先尽可能的吧小丑给一个人,在把剩下的小丑尽可能的平分,最后计算差值即可。#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn,m,k,t;cin>>n>>m>>k,t=n/k;inta=min(m,t);m-=a,k--;intb=(m......
  • clickhouse的安装流程
    使用yum命令安装yuminstallclickhouse-serverclickhouse-client启动/etc/init.d/clickhouse-serverstart日志文件将输出在/var/log/clickhouse-server/文件夹sudoserviceclickhouse-serverstatus连接客户端clickhouse-clientshowdatabase;默认情况下,使用de......
  • Codeforces Round 889 (Div. 2) A-E
    传送门,不用谢。A给出排列每次可以交换两个数字,求最少多少次使得排列为错排。考虑在原位的数字个数为\(cnt\)则答案显然为\((cnt+1)>>1\)B求一个最大区间满足其中说有数字被\(n\)整除极其有趣,注意到样例解释具有迷惑性。考虑一个序列\([l,r]\)为答案那么从中可以看出\(1|n......
  • 火山引擎ByteHouse:云原生数据库如何提升MySQL兼容性?
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群当前各类软件层出不穷,单独某一款软件往往难以满足企业应用需求,一般都需要与各类软件组合使用,这时软件生态兼容性就显得格外重要。作为关系数据库管理系统的代表之一,MySQL支持大多数操作系统、编程......
  • 火山引擎ByteHouse:云原生数据库如何提升MySQL兼容性?
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群当前各类软件层出不穷,单独某一款软件往往难以满足企业应用需求,一般都需要与各类软件组合使用,这时软件生态兼容性就显得格外重要。作为关系数据库管理系统的代表之一,MySQL支持大多数操作......
  • Educational Codeforces Round 152 (Rated for Div. 2)
    Preface经典秒完SB题然后开始坐牢1h,写了个E的假算法T在24个点就不管了打lol去了妈的怎么稍微难点的题就是想不到呢A.MorningSandwich签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>#include<cmath>#include<cstdlib>......