HDU5115 Dire Wolf interval DP Memory search

Source: Internet
Author: User

HDU5115 Dire Wolf interval DP Memory search

For example, like the wolf BB in DOTA, it has attack power, and the halo can improve the attack power of its companions. The wolf stands in a row and the halo can only be provided to neighboring wolves, the attacker needs to take a fight when the wolf is knocked out, and it will also take a fight, so that your blood volume will actually be equal to the attacking power of the wolf.


The equation is very good. dp [I] [j] indicates that the minimum blood volume required by the wolf in the interval [I, j] is dropped. Here is the closed interval. Later we can see that it is 200*200, so I am too lazy to think about the equation transfer, and I can simply perform the memory-based search. Note that a wolf is slaughtered, and the attacking power of the two neighboring wolves will be reduced, therefore, the boundary should be set when searching by interval in the search process. If the result is not completed in the first place, the case has not been run. This is difficult to debug in deep search, and the interval [I, j] [I, k-1] [k + 1, j] are searched separately. keep splitting, and 700 ms is run. The question is given to 5 s, it is estimated that this question has been developed in a matter of seconds with brute force,


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));memset(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<
 
  = 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);printf("Case #%d: ",++Case);cout<
  
   >t;while(t--) {init();if(input())return 0;cal();output();}return 0;}
  
 




Related Article

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.