HDU-2770-Easy Climb

题意:这个题是给你一个序列,然后你对于首尾2个值不能改动,其他的值你可以改动,要求你通过修改使得相邻2个值之差绝对值不超过d,然后修改的代价为修改后的值域原来值差的绝对值之和。

思路:其实白书上面说了一些思路的(新版的小白书),不得不佩服上面提到的修改后的状态必然为hi+kd(1<=i<=n,-n

代码:

#include
#include
#include
#include
using namespace std;
const long long inf=1LL<<62;
const int maxn=110;
const int maxm=maxn*maxn*2;
int n,cnt;
long long h[maxn],s[maxm],dp[maxn][maxm],d;
int q[maxm];
void Init()
{
    for(int i=0;i<=n;i++)
        for(int j=0;j=dp[i-1][now])
                    last--;
                q[last++]=now++;
            }
            while(pres[q[pre]])
                pre++;
            dp[i][j]=abs(h[i]-s[j])+dp[i-1][q[pre]];
        }
    }
    ind=lower_bound(s,s+cnt,h[n])-s;
    if(dp[n][ind]>=inf)
        printf("impossible\n");
    else
        printf("%I64d\n",dp[n][ind]);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        cnt=0;
        scanf("%d%I64d",&n,&d);
        for(int i=1;i<=n;i++)
            scanf("%I64d",&h[i]);
        for(int i=1;i<=n;i++)
            for(long long j=0;j


你可能感兴趣的:(HDU,ACM)