HDU-#4472 Count(DP)
来源:互联网 发布:马龙 王皓 知乎 编辑:程序博客网 时间:2024/06/05 04:06
题目大意:给出n个结点,问能够构成多少种完全对称的树。
解题思路:题目比较难懂的是理解那句要求同一层结点的子结点要求完全一样,就是完全对称的意思。开始以为是规律题,推了很久的都规律,最后还是跪了,看了题解才知道是一道简单DP,之前一直都跳过了DP,看来基础的还是要去学习的!理解了就可以递推出该状态转移方程:dp[i]=sum(dp[j]),(i-1)%j==0.然后根据这个打表即可,详见code。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4472
code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ll __int64const int MAXN = 1e4+10;const int MOD = 1e9+7;ll dp[MAXN];int cas,n;void init(){ memset(dp,0,sizeof(dp)); dp[1]=dp[2]=1; for(int i=3;i<MAXN;++i) for(int j=1;j<i;++j) if((i-1)%j==0) dp[i]=(dp[i]+dp[j])%MOD;}int main(){ //freopen("input.txt","r",stdin); init(); while(~scanf("%d",&n)){ printf("Case %d: %I64d\n",++cas,dp[n]); } return 0;}
0 0
- HDU-#4472 Count(DP)
- hdu 4472 Count dp
- [dp] hdu 4472 Count
- HDU 4472 - Count(计数DP)
- HDU ACM 4472 Count->DP
- hdu 4472 Count DP 递推
- HDU 4472 Count (线性dp 推公式)
- hdu 4472 Count【思维+dp】好题
- HDU 3485 Count 101(简单DP)
- hdu 3336 Count the string(KMP+dp)
- hdu 3336 Count the string (DP+kmp)
- hdu 3336 count the string(KMP+dp)
- HDU Count the string 【dp KMP】(求子串总数)
- Hdu 3336 Count the String(DP+KMP)(好题)
- hdu 3336 Count the string(KMP+dp)
- HDU 3336 Count the string(KMP+DP)
- HDU 3336 Count the string(kmp+dp)
- HDU 3336 Count the string (kmp+dp)
- Android中Adapter之BaseAdapter使用
- 没事看看拉勾网,知道需求
- jQuery,使用on代替delegate,live 写法区别
- OA--对于每个form表单(<s:iterator>生成)的处理
- POJ Goldbach's Conjecture
- HDU-#4472 Count(DP)
- 枚举变量的大小是多少?
- dbms_shared_pool
- 使用elasticsearch提高hbase基于列的查询效率
- "PCH 警告:标头停止点不能位于宏或#if块中"
- 求集合的所有子集
- Ubuntu新建账户终端显示不正常问题
- 谱聚类算法详解
- 西红柿烧茄子---贝太厨房