183. Painting the balls

time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output
Petya puts the N white balls in a line and now he wants to paint some of them in black, so that at least two black balls could be found among any M successive balls. Petya knows that he needs Ci milliliters of dye exactly to paint the i-th ball. Your task is to find out for Petya the minimum amount of dye he will need to paint the balls.
Input
The first line contains two integer numbers N and M (2<=N<=10000, 2<=M<=100, M<=N). The second line contains N integer numbers C1, C2, ..., CN (1<=Ci<=10000).
Output
Output only one integer number - the minimum amount of dye Petya will need (in milliliters).
Sample test(s)
Input
 
 
6 3 
1 5 6 2 1 3
 
 
Output
 
 
9
 
 
Note
Example note: 1, 2, 4, 5 balls must be painted.

思路:dp[i][j]//在i染色,在i-j染色的最小花费 设a b更新到,a b c,由远(距a m-1距c 1)到近以b为中心更新dp即可

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=10001;
const int maxm=101;
const int inf=1e9+5;
int dp[maxn][maxm];//back maxm
int c[maxn];
int n,m;
int main(){
while(scanf("%d%d",&n,&m)==2){
//memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)scanf("%d",c+i);
for(int i=0;i<m;i++){
for(int j=0;j<i;j++){
dp[i][i-j]=c[i]+c[j];//g[i-j]=min(dp[i][j],g[i-j]);
}
}
for(int j=1;j<n;j++){
int minn=inf;
for(int i=min(n,j+m)-1;i>j&&i>=m;i--){
minn=min(dp[j][m+j-i],minn);
dp[i][i-j]=minn+c[i];
}
}
int ans=inf;
for(int i=n-m+1;i<n;i++){
for(int j=min(m-1,i-n+m);j>0;j--)
ans=min(ans,dp[i][j]);
}
printf("%d\n",ans);
}
return 0;
}

  

 

sgu 183. Painting the balls 动态规划 难度:3的更多相关文章

  1. SGU 183. Painting the balls( dp )

    dp..dp(i, j)表示画两个点为i-j, i的最优答案. dp(i, j) = min{ dp(i-j, k) } + cost[i] (1≤k≤M-j) 令f(i, j) = min{dp(i ...

  2. SGU 183 Painting the balls (优化的动态规划)

    题意:给n个白球,选其中一些涂为黑色,且给了涂第i个球的花费为ci,要求每m个连续的球中至少有两个黑球,问最小花费是多少? 容易想到一个方程dp[i][j]=min{dp[k][i]}+c[j] dp ...

  3. SGU 183.Painting the balls

    时间限制:0.25s 空间限制:4M 题意:  在n(n<=10000)个球中,给若干个球涂色,每个球涂色的代价为Ci,使得任意连续m(m<=100)个球中有至少两个球被涂了色. Solu ...

  4. poj 3783 Balls 动态规划 100层楼投鸡蛋问题

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098409.html 题目链接:poj 3783 Balls 动态规划 100层楼投鸡蛋问题 ...

  5. Codeforces 264C Choosing Balls 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF264C.html 题目传送门 - CF264C 题意 给定一个有 $n$ 个元素的序列,序列的每一个元素是个 ...

  6. SCU3037 Painting the Balls

    Description Petya puts the \(N\) white balls in a line and now he wants to paint some of them in bla ...

  7. UVa LA 3882 - And Then There Was One 递推,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  9. ZOJ 3161 Damn Couples 动态规划 难度:2

    Damn Couples Time Limit: 1 Second      Memory Limit: 32768 KB As mentioned in the problem "Coup ...

随机推荐

  1. script 加载顺序问题的延展研究

    今天群里有人问为什么会出现脚本的加载顺序与定义脚本顺序不一致的问题,这个问题引起了我的好奇,经过一番调研,有了这篇文章. 这是一个伪命题吗? 首先,W3C 推荐 script 脚本应该被立即加载和执行 ...

  2. 【第二十九章】 springboot + zipkin + mysql

    zipkin的数据存储可以存在4个地方: 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了) 这也是之前使用的 mysql 可能是最熟悉的方式 es Cassandra ...

  3. [TODO]The way to Go(9): 基本类型和运算符

    参考: Github: Go Github: The way to Go 基本类型和运算符 表达式是一种特定的类型的值,它可以由其它的值以及运算符组合而成. 每个类型都定义了可以和自己结合的运算符集合 ...

  4. 解决复制到keil编辑器中汉字出现乱码情况

    https://blog.csdn.net/dxuehui/article/details/51123372 1.在菜单栏中选择'Edit'选项. 2.'Edit'选项中选择'Configuratio ...

  5. UVa 12108 特别困的学生

    https://vjudge.net/problem/UVA-12108 题意:给出n个学生的“清醒—睡眠”周期和初始时间点,每个学生在睡眠时需要判断全班睡觉人数是否严格大于清醒人数,否则在坚持一个清 ...

  6. mysql中index与Multiple-Column Indexes区别与联系

    索引对提升SELECT/UPDATE语句查询速度有着立竿见影的效果,有索引和无索引,查询速度往往差几个数量级. 本次讨论一下index(每列作为一个索引,单列索引)和Multiple-Column I ...

  7. clipboard异步复制文本(动态获取文本)

    1.需求描述: 点击“分享”按钮的时候,发送 ajax 请求获得动态邀请连接,成功取得数据后复制到剪贴板 2.解决重点: > Clipboard 动态设置文本的使用 > Ajax请求设置为 ...

  8. Linux——进程管理简单学习笔记(二)

    计划任务: 为什么要设置计划任务 : 实现数据库备份,发送系统通知神马的..... 计划任务的命令: 一: at :  安排作业在某一时刻执行一次 nbatch    安排作业在系统负载不重时执 行一 ...

  9. python 斐波那契查找

    def fibonacci_search(lis, key): # F = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 ...

  10. kali linux下几个更新命令的区分

    首先更新命令有:apt-get update ,apt-get upgrade ,apt-get dist-upgrade等三个: (1)apt-get update:只更新软件包的索引源,作用:同步 ...