http://poj.org/problem?id=1160

算水过的吧 四重循环没优化 CZ说爆可过 就爆了

dp[i][j] = min(dp[i][j],dp[i-1][g]-s) 第i个点建在第j个村庄上 s 是这个点比上个点少的距离

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 1010
#define INF 0xfffffff
int h[N],dp[][N];
int main()
{
int i,j,k,n,m,g;
scanf("%d%d",&n,&m);
for(i = ; i <= n; i++)
scanf("%d",&h[i]);
for(i = ; i <= n ; i++)
{
int s = ;
for(j = ; j <= n ; j++)
s+=abs(h[j]-h[i]);
dp[][i] = s;
}
for(i = ; i <= m ; i++)
for(j = i ; j <= n ; j++)
{
dp[i][j] = INF;
for(g = i-; g < j ; g++)
{
int s=,ss=;
for(k = g+ ; k < j; k++)
{
s+=min(h[k]-h[g],h[j]-h[k]);
ss+=(h[k]-h[g]);
}
dp[i][j] = min(dp[i][j],dp[i-][g]-ss-(h[j]-h[g])*(n-j+)+s);
}
}
int minz=INF;
for(i = m; i <= n ; i++)
minz = min(minz,dp[m][i]);
printf("%d\n",minz);
return ;
}

poj1160Post Office(DP)的更多相关文章

  1. poj1106-Post Office(DP)

    Description There is a straight highway with villages alongside the highway. The highway is represen ...

  2. 【noi 2.6_162】Post Office(DP)

    这题和"山区建小学"除了输入不同,其他都一样.(解析可见我的上一篇随笔) 但是,这次我对dis[][]加了一个优化,画一下图就可明白. 1 #include<cstdio&g ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. OI中神奇的神器fillchar

    传说,Pascal中有一个函数——fillchar.这是高手们装*用的利器,也是大家的神器(大家好才是真的好). 神器介绍: 百度百科说:“Fillchar是Turbo/Borland Pascal的 ...

  2. Eclipse查看历史代码

    选中要查看的文件(.class等) 右击->Team->Show Local History

  3. File Operation using SHFileOperation

    SHFILEOPSTRUCT Original link: http://winapi.freetechsecrets.com/win32/WIN32SHFILEOPSTRUCT.htm Refere ...

  4. Poj 2159 / OpenJudge 2159 Ancient Cipher

    1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...

  5. Linux C 程序 输入输出函数(THREE)

    标准输入输出函数#include<stdio.h>stdio 是 standard input & output 的缩写 字符数据输入输出函数: putchar() , getch ...

  6. android xml产生和解析

    public static void writeToXml(Map<String, Object> map,Writer writer) throws Exception, Illegal ...

  7. js电话号码正则校验--座机和手机号

    1.最新的电话号码段: 移动:134(1349除外)135 136 137 138 139 147 150 151 152 157 158 159 182 183 184 187 188 联通: 13 ...

  8. python正则的中文处理

    因工作需要,要查找中文汉字分词,因为python正则表达式\W+表示的是所有的中文字就连标点符号都包括.所以要想办法过滤掉. 参考博客:http://log.medcl.net/item/2011/0 ...

  9. ubuntu10.04搭建嵌入式开发环境

    改源 配置vim set number set autoindent set smartindent set tabstop=4 set incsearch 安装g++ 配置samba 1.先安装程序 ...

  10. GPU CUDA常量内存使用

    #include <cuda.h> #include <stdio.h> int getMulprocessorCount(){ cudaDeviceProp prop; cu ...