Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) D. Singer House(dp)
来源:互联网 发布:安卓java游戏 编辑:程序博客网 时间:2024/04/29 14:11
题目链接:http://codeforces.com/contest/830/problem/D
dp[i][j]表示i层,有j个不相容的路径的方案数,每次加入一个根节点有四种情况,选根节点为一个单独的路径,不选根节点,选根节点和左/右子树某个路径相连,选根节点将两个路径连在一起。用long long会T,具体转移方程看题解。
代码:
#include<bits/stdc++.h>using namespace std;const int MAXN=505;const int MOD=1e9+7;typedef long long ll;int dp[MAXN][MAXN];void add(int &a,int b){a+=b;if(a>=MOD)a-=MOD;}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int n;scanf("%d",&n);dp[1][0]=1,dp[1][1]=1;for(int i=1;i<n;i++){for(int l=0;l<=n;l++){for(int r=0;r<=n;r++){int sum=((ll)dp[i][l])*dp[i][r]%MOD;if(l+r+1<=n)add(dp[i+1][l+r+1],sum);if(l+r<=n){add(dp[i+1][l+r],sum);add(dp[i+1][l+r],(ll)sum*2%MOD*(l+r)%MOD);}if(l+r-1<=n&&l+r-1>=0){add(dp[i+1][l+r-1],(ll)sum*((l+r)*(l+r-1)/2)%MOD*2%MOD);}}}}printf("%d\n",dp[n][1]);return 0;}
阅读全文
0 0
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) D. Singer House(dp)
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) C. Bamboo Partition(数学)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)D. Office Keys(二分+贪心)
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) E. Rusty String(fft)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)C. Jury Marks
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) ..C. Jury Marks
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)-831C Jury Marks(思维)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) 总结
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)-模拟-C. Jury Marks-
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) E Cards Sorting
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) F. Bamboo Partition
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) 简单暴力
- Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) C DNA Evolution
- 你还在为安装不上NETFramework3.5而重装系统么?
- JAVA通过JDBC连接数据库
- 沙漠露营 优质点评
- <小程序>修改button组件的样式
- Python学习笔记(6)测试
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) D. Singer House(dp)
- python中文件基本操作命令及注意事项
- java容器
- 微信小程序支付 后端PHP
- 【51nod 扔盘子】+ 预处理
- poj1094 Sorting It All Out【拓扑排序】
- Linux 系统服务管理
- 获取泛型的真实类型
- JS兼容问题