51nod 1412 AVL tree Type (DP)

Source: Internet
Author: User

Topic Links: Types of 51nod 1412 AVL trees

When I started to do it, I turned the depth too small. The result has been WA, I was naïve.

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 using namespacestd;6typedefLong Longll;7 Const intMoD = 1e9+7;8 Const intN =2001;9ll dp[n][ -];//Dp[i][k] I: Number of nodes, K: DepthTen voidsolve () { One     intI, J, K; Adp[0][0] = dp[1][1] =1; -      for(i =2; i < N; ++i) { -          for(k =2; K < -; ++k) { the              for(j =0; J < I; ++j) { -                 //J is the number of nodes in the right subtree, and the sum of the i-1 nodes is -                 //The left and right sub-tree depth same -Dp[i][k] + = dp[i-1-j][k-1] * dp[j][k-1]; +                 //left and right sub-tree depth difference one -Dp[i][k] + =2* dp[i-1-j][k-2] * dp[j][k-1]; +DP[I][K]%=MoD; A             } at         } -     } - } - intMain () { -     intn, I; -ll ans =0; in solve (); -scanf"%d", &n); to      for(i =1; I < -; ++i) { +Ans + =Dp[n][i]; -     } theAns%=MoD; *printf"%lld\n", ans); $     return 0;Panax Notoginseng}
View Code

51nod 1412 AVL tree Type (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.