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;}