HDU5115 Dire Wolf interval DP Memory search

Source: Internet
Author: User

Test instructions: For example, like the Wolf BB in DotA, its own attack, but also the halo can enhance the attack of the companion, the Wolf standing in a row, the halo can only provide to the adjacent wolves, knocked out the wolf need to hit a bit, and it will also play, so that your blood amount is actually equal to the wolf's attack


The equation is very good to think, Dp[i][j] represents the i,j of the attack interval [the wolf] the minimum amount of blood, here is the closed interval, and then see is 200*200, then lazy to think of the equation transfer, direct memory search can be, note that a wolf was slaughtered, its adjacent sides of the two wolf attack will be reduced, So the search process partition between the search boundary to be set well, at the beginning of the case has not been run out, this deep search debugging is still more troublesome, directly from the interval [i,j] inside began to search [i,k-1] [k + 1,j], has been divided, so run out of 700ms, the topic gave 5s, estimated this The topic has a second method plus violence made out,


int T;int N;int aa[200 + 55],bb[200 + 55];int dp[200 + 55][200 + 55];int case = 0;void init () {memset (dp,-1,sizeof (DP)); me Mset (aa,0,sizeof (AA)); memset (Bb,0,sizeof (BB));} bool Input () {while (cin>>n) {for (int i=1;i<=n;i++) cin>>aa[i];for (int i=1;i<=n;i++) cin>>bb[i ];return false;} return true;} int dfs (int l,int r) {if (Dp[l][r]! =-1) return dp[l][r];//cout<<l<< "* * * *" <<r<<endl;if (L = = r) return dp[l][r] = Aa[l] + bb[l-1] + bb[l + 1];int now = inf;for (int i=l;i<=r;i++) {//cout<<l<< "----" <& Lt;i-1<<endl;//cout<<i + 1<< ".&&&&" <<r<<endl;int tmp = aa[i];if (L < = i-1) tmp + = DFS (l,i-1), if (r >= i + 1) tmp + = DFS (i + 1,r); now = min (now,tmp);} return Dp[l][r] = now + bb[l-1] + bb[r + 1];} void Cal () {DFS (1,n);p rintf ("Case #%d:", ++case); Cout<<dp[1][n]<<endl;} void output () {}int main () {cin>>t;while (t--) {init (); if (input ()) return 0;cal (); output ();} return 0;}




HDU5115 Dire Wolf interval DP Memory search

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.