“玲珑杯”ACM比赛 Round #18---图论你先敲完模板(DP+思维)

题目链接

 

DESCRIPTION

INPUT

OUTPUT

SAMPLE INPUT

2

3 2

3 5 7

3 10

3 5 7

SAMPLE OUTPUT

12

26

HINT

官方题解:

               

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
long long dp[100005];
int a[100005];

int main()
{
    ///cout << "Hello world!" << endl;
    int T;  cin>>T;
    while(T--)
    {
        int n;  long long x;
        scanf("%d%lld",&n,&x);
        for(int i=1;i<=n;i++)  scanf("%d",&a[i]);

        dp[0]=0;  dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            dp[i]=1e18+3;
            int j=i-60;
            if(j<1) j=1;
            for(;j<=i;j++)
            {
                int s=a[i]-a[j];
                if(s<60){
                long long t=dp[j]+(1LL<<s)+x;
                   dp[i]=min(dp[i],t);
                }
                //cout<<"t-----"<<i<<"-----"<<j<<"-----"<<t<<endl;
            }
        }
        printf("%lld\n",dp[n]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/chen9510/p/7192028.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值