【DP】 hdu3933 Dark Parth

Dark Parth

http://acm.hdu.edu.cn/showproblem.php?pid=3933



Problem Description
In the dark path, the single figure is walking difficultly in the listless rainfall. No one knows his real destination.

‘Young, have you ever tasted the loneliness walking in dark path; have you ever run about madly just to avoid the pain in the deep heart?'
After BiYao's death, XiaoFan changed to GuiLi .Running in such darkness, leaving the rain wet out his clothes, leaving the darkness cover up his eyes, he will never regret!

Now, we separate the path into n parts with the same length (1<=N<=1000).Every part has its value Ai (-1000<=Ai<=1000). If Xiaofan walks through the ith part of the path, he will get the hurt Ai. His trump ShaoHuoGun will give him S chances to fly (1<=S<=100). Every chance can help him get through one part of the path without any hurt. But there’s a limit: The length of his fly Si should be longer than La and shorter than Lb (1<=La<=Si<=Lb<=n).
Your job is to find the best way for XiaoFan to have the least hurt.
Hit: Two different fly paths can't cover each other, and times of fly can be fewer than the given times S.
 

Input
There are several test cases. The first line is an integer N, then the second line have three integers Lb, La, S, then followed N integers A1.A2…An.The test end by n = 0.
 

Output
The value of least hurt.
 

Sample Input
  
  
10 3 2 3 3 1 -5 -9 2 -1 1 -7 9 10 10 4 3 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0
 

Sample Output
  
  
-21 -10


#include<cstdio>
#include<cstring>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define inf ((1<<30)-1)
int num[1005];
int dp[1005][105];//dp[i][j]在第i个位置跳了j次
//dp[i][j]=min(dp[i-1][j]+num[i],min{dp[i-k][j-1]}(la<=k<=lb));
//             第i位不跳
int main()
{
    int n,s,la,lb,ans;
    for(;~scanf("%d",&n),n;)
    {
        ans=inf;
        scanf("%d%d%d",&lb,&la,&s);
        //初始化
        for(int i=0;i<=n;++i)
            for(int j=0;j<=s;++j)
                dp[i][j]=inf;
        dp[0][0]=0;
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&num[i]);
            dp[i][0]=dp[i-1][0]+num[i];
        }
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=s;++j)
            {
                dp[i][j]=dp[i-1][j]+num[i];
                for(int k=la;i-k>=0&&k<=lb;++k)
                    dp[i][j]=min(dp[i][j],dp[i-k][j-1]);
            }
        }
        for(int i=0;i<=s;++i)
            ans=min(ans,dp[n][i]);
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值