[DP] DP, hdu5115 in the Wolf interval of HDU 5115 Dire

Source: Internet
Author: User

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


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.