Hdu5115-dire Wolf (interval dp)

Source: Internet
Author: User

The problem is the interval DP.

The problem is that AI means that each wolf has its own attack power, BI indicates that it can provide the attack to the neighboring wolves, and in what order to kill the Wolf, the wolf can attack the person least.

And if the wolf is killed, it will not be able to provide damage to the neighboring wolves.

The dynamic transfer equation is dp[i][j]=min (dp[i][k]+dp[k][j]+a[k]+a[i]+a[j],dp[i][j]) (j<k<i);

I indicates that the first wolf is the right end (not yet chopped), J indicates that the head of the first wolf is the left end (not yet killed).

DP[I][J] records the smallest attack that I-j has chosen when I,j is not selected.

(This problem does me ....) Spent almost a day, in the middle of thinking about a daze, just this state. Still lazy,,,, but now do not think too clear ... )。

First, a, b array at both ends to add a bit, a[0]=0;b[0]=0;a[p+1]=0;b[p+1]=0;

Because to kill all the wolves, because every time there are two ends, so to kill it must be 0-p+1 within the number 1 to P Wolf, 1 left, p right end must have an endpoint. The final answer is dp[p+1][0];

Get back to the code before you finish the lesson:

1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <stdlib.h>5#include <string.h>6 using namespacestd;7 Long Longn=1e16;8typedefLong Longll;9 intMainvoid)Ten { One     inti,j,k,p,q; All dp[ -][ -]; -ll a[ -]; -ll b[ -]; thescanf"%d",&k); -      for(i=1; i<=k; i++) -     { -scanf"%d",&p); +Memset (A,0,sizeof(a)); -memset (b,0,sizeof(b)); +          for(j=1; j<=p; J + +) Ascanf"%lld",&a[j]); at          for(j=1; j<=p; J + +) -scanf"%lld",&b[j]); -         intn,m,t; -Memset (DP,0,sizeof(DP)); -          for(n=2; n<=p+1; n++) -         { in              for(m=n-2; m>=0; m--) -             { todp[n][m]=dp[n][n-1]+dp[n-1][m]+a[n-1]+b[n]+B[m]; +                  for(t=n-1; t>m; t--) -                 { the  *Dp[n][m]=min (dp[n][t]+dp[t][m]+b[n]+a[t]+b[m],dp[n][m]); $                 }Panax Notoginseng             } -  the         } +printf"Case #%d:%lld\n", i,dp[p+1][0]); A     } the     return 0; +  -}

Hdu5115-dire Wolf (interval 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.