Codevs 1090 plus two fork tree

Source: Internet
Author: User

/*based on the nature of the middle sequence traversal and the quasi-recursive processing of the subtree well, it's a stone merge. However, the boundary is not always written and the cycle sequence is written in the memory .... The optimal value of each interval is separated by that point, that is, who is the root of the subtree and then recursively outputs to note that the left subtree is handed to the right subtree .*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 35using namespacestd;intN,f[maxn][maxn],v[maxn],c[maxn][maxn],pre[maxn],len;voidDfs (intLintR) {    if(L>r)return; intk=C[l][r]; pre[++len]=K; Dfs (L,k-1);D FS (k +1, R);}intDP (intLintR) {    if(r<l)return 1; if(F[l][r])returnF[l][r];  for(inti=l;i<=r;i++)      {          intK=DP (l,i-1) *DP (i+1, R) +V[i]; if(k>F[l][r]) {F[l][r]=k;c[l][r]=i; }      }    returnf[l][r];}intMain () {//freopen ("jfecs.in", "R", stdin); //freopen ("Jfecs.out", "w", stdout);scanf"%d",&N);  for(intI=1; i<=n;i++) scanf ("%d",&V[i]);  for(intI=1; i<=n;i++) F[i][i]=v[i],c[i][i]=i; printf ("%d\n", DP (1, N)); Dfs (1, N);  for(intI=1; i<=n;i++) printf ("%d", Pre[i]); return 0;}

Codevs 1090 plus two fork tree

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.