博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Grand Contest 004 : Colorful Slimes (DP)
阅读量:4599 次
发布时间:2019-06-09

本文共 2237 字,大约阅读时间需要 7 分钟。

Colorful Slimes

时间限制: 2 Sec  
内存限制: 256 MB
提交: 235  
解决: 36
[ ][ ][ ][命题人: ]

题目描述

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.

来源

    

【题意】

要获得n中颜色,  有两种操作

 一 直接制造  花费时间a[i]秒

二 现拥有的全部转换  i-1 -> i    ,i -> i+1,   i+1 -> i+2   花费时间x 秒

问获得n 种颜色 需要 最少时间;

dp[i][j]      i 代表制作第i 个颜色,  j 代表转换次数;

最优 应该为  k*x + sum( dp[i][k]) 

先dp  每种颜色 最优的策略 ,  然后  计算  k中 转换里  sum 和 最小的。  加上 k*x

因为  是 转换一次, 那么 全部都需要 转换,所有 n 中颜色 实际上 是 一体的。

【code】

#include
using namespace std;const int N=2000+10;typedef long long ll;const ll llf=(1ll<<63)-1;ll dp[N][N],a[N];int main(){ int n; ll x,ans=llf; scanf("%d%lld",&n,&x); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); dp[0][i]=a[i]; } for(int i=1;i<=n-1;i++) { for(int j=1;j<=n;j++) { int ind=j-i; if(ind<=0) ind=n+ind; dp[i][j]=min(dp[i-1][j],a[ind]); } } for(int i=0;i<=n-1;i++) { ll ant=0; for(int j=1;j<=n;j++) ant+=dp[i][j]; ans=min(ans,ant+i*x); // cout<
<

123 

转载于:https://www.cnblogs.com/sizaif/p/8822634.html

你可能感兴趣的文章
MeetMe
查看>>
IP报文格式及各字段意义
查看>>
(转载)rabbitmq与springboot的安装与集成
查看>>
C2. Power Transmission (Hard Edition)(线段相交)
查看>>
STM32F0使用LL库实现SHT70通讯
查看>>
Atitit. Xss 漏洞的原理and应用xss木马
查看>>
MySQL源码 数据结构array
查看>>
(文件过多时)删除目录下全部文件
查看>>
T-SQL函数总结
查看>>
python 序列:列表
查看>>
web移动端
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
linux 装mysql的方法和步骤
查看>>
poj3667(线段树区间合并&区间查询)
查看>>
51nod1241(连续上升子序列)
查看>>
SqlSerch 查找不到数据
查看>>