hoj1965 Ferry Loading II

/*This Code is Submitted by billforum for Problem 1965 at 2012-02-06 21:00:43*/
#include <iostream>
using namespace std;

const int NUM=1442;//the number of the most cars
int m[NUM+1],step[NUM+1],tmp[NUM+1],pre[NUM+1];

int max(int x,int y)
{
        return(x>y?x:y);
}
int main(int args,char** argv)
{
        int time,lim,num,test;
        cin>>test;
        while(test--)
        {
                cin>>lim>>time>>num;
                for(int i=1;i<=num;i++)
                        {
                                cin>>tmp[i];
                                //step[i]=0;
                                m[i]=-1;
                                //min[i]=tmp[i]+time;
                        }
                m[0]=-time;// 
                //step[0]=0;
                m[1]=tmp[1]+time;
                pre[1]=0;
                //step[1]=1;
                for(int i=2;i<=num;i++)
                {
                        int maxn=100000000;
                        for(int j=1;(j<=lim)&&(i-j>=0);j++)
                        {
                                int t=max(m[i-j]+time,tmp[i])+time;//!!!!!!!
                                 if(t<=maxn)
                                 {
                                        maxn=t;
                                         m[i]=t;
                                        //step[i]=step[i-j]+1;
                                        pre[i]=i-j;
                                 }
                                 
                        }
                }
                int ans=0,id=num;
                while(pre[id]!=0)
                {
                        ans++;
                        id=pre[id];
                }
                ans++;
                cout<<m[num]<<" "<<ans<<endl;
        }
        return 0;
}

 

转载于:https://www.cnblogs.com/wuzhibin/archive/2012/02/08/2343036.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值