[树形DP] BZOJ 4824 [Cqoi2017]老C的键盘
来源:互联网 发布:二级vb软件序列号 编辑:程序博客网 时间:2024/06/04 17:40
首先这是棵完全二叉树
直接
然后合并就是两个排列合并咯 组合数乘一下 大于小于都差不多
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;typedef long long ll;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}inline void read(char *s){ char c=nc(); int len=0; for (;!(c=='<' || c=='>');c=nc()); for (;c=='<' || c=='>';s[++len]=c,c=nc());}const int N=105;const int P=1e9+7;int n;char s[N];struct edge{ int u,v,next;}G[N];int head[N],inum;inline void add(int u,int v,int p){ G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;}#define V G[p].vll C[N][N],f[N][N];ll g[N];int size[N];inline void dfs(int u){ size[u]=1; for (int p=head[u];p;p=G[p].next) dfs(V); f[u][1]=1; for (int p=head[u];p;p=G[p].next){ int n=size[u],m=size[V]; for (int i=1;i<=n+m;i++) g[i]=0; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (s[V]=='>') for (int x=j;x<=m;x++) g[x+i]+=f[u][i]*f[V][j]%P*C[i+x-1][x]%P*C[n+m-i-x][m-x]%P; else for (int x=0;x<j;x++) g[x+i]+=f[u][i]*f[V][j]%P*C[i+x-1][x]%P*C[n+m-i-x][m-x]%P; for (int i=1;i<=n+m;i++) f[u][i]=g[i]%P; size[u]+=size[V]; }}int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(s+1); for (int i=2;i<=n;i++) add(i/2,i,++inum); C[0][0]=1; for (int i=1;i<=n;i++) { C[i][0]=1; for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%P; } dfs(1); ll ans=0; for (int i=1;i<=n;i++) ans+=f[1][i]; printf("%d\n",ans%P); return 0;}
0 0
- [树形DP] BZOJ 4824 [Cqoi2017]老C的键盘
- Bzoj 4824: [Cqoi2017]老C的键盘
- 4824: [Cqoi2017]老C的键盘
- 【BZOJ4824】 [Cqoi2017]老C的键盘
- BZOJ 4813: [Cqoi2017]小Q的棋盘 (树形dp)
- bzoj 4813: [Cqoi2017]小Q的棋盘 树形dp
- [最小割] BZOJ 4823 [Cqoi2017]老C的方块
- BZOJ 4823: [Cqoi2017]老C的方块(最小割)
- 【CQOI2017】老C的方块
- 4822: [Cqoi2017]老C的任务&&bzoj 1935: [Shoi2007]Tree 园丁的烦恼
- NKOJ 4043 (CQOI 2017) 老C的键盘 (树形DP)
- 【CQOI2017】bzoj4822 老C的任务
- 【CQOI2017】bzoj4823 老C的方块
- 4822: [Cqoi2017]老C的任务
- 4823: [Cqoi2017]老C的方块
- 【BZOJ4822】 [Cqoi2017]老C的任务
- 【BZOJ4823】 [Cqoi2017]老C的方块
- bzoj4822 cqoi2017 老C的任务【树状数组+扫描】
- VS2008 引用Oracle.ManagedDataAccess.dll报错的问题
- linux端口解释
- hdu 5571 tree (动态点分治)
- SQL 的备份与还原
- 光栅化
- [树形DP] BZOJ 4824 [Cqoi2017]老C的键盘
- 洛谷 P2825 [HEOI2016]游戏
- TP框架---验证码
- AS3加密解密Des
- ZOJ3950统计
- 明文和密文是什么意思,以及flex与后台交互,Flex根据明文和密钥,采用DES加密算法进行加密,生成密文。
- linux如何去空格
- yolo windows 版本
- [几何] BZOJ 4814 [Cqoi2017]小Q的草稿