AT - Grand - 004 - B - Colorful Slime

问题 H: Colorful Slimes

时间限制: 2 Sec   内存限制: 256 MB
提交: 213   解决: 29
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together.

Snuke can perform the following two actions:

Select a color i (1≤i≤N), such that he does not currently have a slime in color i, and catch a slime in color i. This action takes him ai seconds.

Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i (1≤i≤N−1) will become color i+1, and the color of a slime in color N will become color 1. This action takes him x seconds.

Find the minimum time that Snuke needs to have slimes in all N colors.

Constraints
2≤N≤2,000
ai are integers.
1≤ai≤109
x is an integer.
1≤x≤109

输入

The input is given from Standard Input in the following format:

N x
a1 a2 … aN

输出

Find the minimum time that Snuke needs to have slimes in all N colors.

样例输入

2 10
1 100

样例输出

12

提示

Snuke can act as follows:

Catch a slime in color 1. This takes 1 second.
Cast the spell. The color of the slime changes: 1 → 2. This takes 10 seconds.

Catch a slime in color 1. This takes 1 second.


原题连接:https://agc004.contest.atcoder.jp/tasks/agc004_b

刚开始考虑每个点的最优,后来发现读错了题意,日常背读错题意的锅。

有N种颜色,他希望把所有的颜色都获得,问你最小花费的时间。

每次他可以选择两种操作中的其中一种

① 直接获得  花费 ai时间

②当前当前颜色已经获得了的话    可以往右移动  i->i+1  i颜色变成i+1  n->1       (移动的时候是已经获得的所有的颜色都移动,刚开始理解错了,所以一直不对,这样就不能考虑每个点的最优解)

所以就变成了,对所有的点移动K次之后的花费求和 然后求最小值 

因为考虑当前点只从前边或者后边移动过来的,就是考虑移动K次 对于每个点的最小值(考虑在那个点进行点亮)

更详细的题解:https://blog.csdn.net/dreams___/article/details/79318750

ll dp[2005][2005];
ll a[2005];
int main (){
    int n;
    ll x;
    scanf ("%d%lld",&n,&x);
    for (int i=1;i<=n;i++) scanf ("%lld",&a[i]);
    for (int i=1;i<=n;i++){
        dp[i][0]=a[i];
        for (int j=1;j<n;j++)
            if((i-j)<=0) dp[i][j]=min(dp[i][j-1],a[(n+i-j)]);
            else dp[i][j]=min(dp[i][j-1],a[i-j]);
    }
    ll minn=(ll)1<<62;
    for (int j=0;j<n;j++){
        ll sum=0;
        for (int i=1;i<=n;i++) sum+=dp[i][j];
        minn=min(minn,sum+(ll)j*x);
    }
    printf("%lld\n",minn);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/passer__/article/details/79893835
今日推荐