HDU 1294 Rooted Trees Problem
生活随笔
收集整理的這篇文章主要介紹了
HDU 1294 Rooted Trees Problem
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目大意:求有n個節點的樹有幾種?
題解:http://www.cnblogs.com/keam37/p/3639294.html
#include <iostream> typedef long long LL; using namespace std; LL f[41]; int cnt[41],n; LL C(LL n,LL m){m=m<(n-m)?m:(n-m);LL ans=1;for(int i=1;i<=m;i++)ans=ans*(n-i+1)/i;return ans; } int dfs(int temp,int left){if(left==0){LL ans=1;for(int i=1;i<=n;i++){if(cnt[i]==0)continue;ans=ans*C(f[i]+cnt[i]-1,cnt[i]);}f[n]+=ans; return 0;}for(int i=temp;i<=left;i++)cnt[i]++,dfs(i,left-i),cnt[i]--;return 0; } int main(){f[1]=f[2]=1;for(n=3;n<=40;n++)dfs(1,n-1);while(cin>>n)cout<<f[n]<<endl;return 0; }轉載于:https://www.cnblogs.com/forever97/p/3668636.html
總結
以上是生活随笔為你收集整理的HDU 1294 Rooted Trees Problem的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 1561
- 下一篇: JAVA I/O流工具类TextFile