51nod 1412 AVL樹的種類(dp)

來源:互聯網
上載者:User

標籤:const   amp   blocks   分享   type   cat   ace   scan   font   

題目連結:51nod 1412 AVL樹的種類

開始做的時候把深度開得過小了結果一直WA,是我天真了。。

 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 using namespace std; 6 typedef long long ll; 7 const int mod = 1e9+7; 8 const int N = 2001; 9 ll dp[N][16];//dp[i][k]  i:節點數, k:深度10 void solve(){11     int i, j, k;12     dp[0][0] = dp[1][1] = 1;13     for(i = 2; i < N; ++i){14         for(k = 2; k < 16; ++k){15             for(j = 0; j < i; ++j){16                 //j為右子樹的節點數,左右子樹節點之和為i-117                 //左右子樹深度相同18                 dp[i][k] += dp[i-1-j][k-1] * dp[j][k-1];19                 //左右子樹深度差一20                 dp[i][k] += 2 * dp[i-1-j][k-2] * dp[j][k-1];21                 dp[i][k] %= mod;22             }23         }24     }25 }26 int main(){27     int n, i;28     ll ans = 0;29     solve();30     scanf("%d", &n);31     for(i = 1; i < 16; ++i){32         ans += dp[n][i];33     }34     ans %= mod;35     printf("%lld\n", ans);36     return 0;37 }
View Code

 

51nod 1412 AVL樹的種類(dp)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.