HDU 1520:anniversary Party Tree DP Foundation

Source: Internet
Author: User

Anniversary party Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=1520

Test instructions

There are a bunch of people in the company to party, everyone has a happy value, these people have a number of subordinate relations, and everyone does not want to and his direct boss (that is, father, not including ancestors) at the same time on the parties, to the party on the largest happy value of the combined.

Exercises

By test instructions know the company members can form a tree, set value[x] for the x is the root node of the maximum weight of the subtree, child[x] is the child node of x, from the tree can be seen, Value[x]=max (value[x]+∑value[child[child[ X]]],∑VALUE[CHILD[X]])

             

Code

#include <stdio.h>
#include <string.h>
const int N=20;
Double dp[1<<n],p[n],x;
int main ()
{
int n;
while (~SCANF ("%d", &n))
{
dp[(1<<n) -1]=0.0;
for (int i=0;i<n;++i)
scanf ("%lf", &p[i]);
for (int j= (1<<n) -2;j>=0;--j)
{
x=0;dp[j]=0.0;
for (int k=0;k<n;++k)
{
if (! ( (1<<k) &j))
dp[j]+=dp[j+ (1<<k)]*p[k],x+=p[k];
}
dp[j]= (dp[j]+1.0)/x;
}
printf ("%.5f\n", dp[0]);
}
}

  

HDU 1520:anniversary Party Tree DP Foundation

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.