[DP] DP, hdu5115 in the Wolf interval of HDU 5115 Dire
Click Open Link
Question: The attacking power of a wolf = the attacking power of the wolf + the bonus of the neighboring wolf on both sides
Each time a wolf is killed, it will receive an attack.
Minimum and minimum attacks
Relatively bare interval DP
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <set>#include <vector>#include <deque>#include <map>#define cler(arr, val) memset(arr, val, sizeof(arr))#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;const int MAXN = 230+1;const int MAXM = 140000;const int INF = 0x3f3f3f3f;const int mod = 1000000007;int a[3000],b[3000];int dp[300][300];int dfs(int l,int r){ if(l+1>=r) return 0; if(dp[l][r]!=-1) return dp[l][r]; dp[l][r]=INF; for(int i=l+1;i<r;i++) { dp[l][r]=min(dp[l][r],dfs(l,i)+dfs(i,r)+a[i]+b[l]+b[r]); } return dp[l][r];}int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);#endif int t,n,cas=1; cin>>t; while(t--) { cin>>n; cler(dp,-1); a[0]=b[0]=a[n+1]=b[n+1]=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); printf("Case #%d: %d\n",cas++,dfs(0,n+1)); } return 0;}