hdu 3666 Making the Grade
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define INF 100000000000000
#define maxn 2005
using namespace std;
int n;
typedef long long LL;
LL a[maxn],b[maxn];
LL dp[maxn][maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
b[i]=a[i];
}
sort(b+,b++n);
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
dp[i][j]=INF;
for(int j=; j<=n; j++)
{
dp[][j]=(a[]-b[j]);
if(dp[][j]<)
dp[][j]=-dp[][j];
} for(int i=; i<=n; i++)
{
LL k=dp[i-][];
for(int j=; j<=n; j++)
{
k=min(dp[i-][j],k);
LL tem=(a[i]-b[j]);
if(tem<)
tem=-tem;
dp[i][j]=min(dp[i][j],k+tem);
// printf("==%I64d\n",dp[i][j]);
}
}
LL minn=INF;
for(int i=; i<=n; i++)
minn=min(minn,dp[n][i]);
printf("%I64d\n",minn);
}
return ;
}
hdu 3666 Making the Grade的更多相关文章
- POJ 1364 / HDU 3666 【差分约束-SPFA】
POJ 1364 题解:最短路式子:d[v]<=d[u]+w 式子1:sum[a+b+1]−sum[a]>c — sum[a]<=sum[a+b+1]−c−1 ...
- POJ 3666 Making the Grade(数列变成非降序/非升序数组的最小代价,dp)
传送门: http://poj.org/problem?id=3666 Making the Grade Time Limit: 1000MS Memory Limit: 65536K Total ...
- Poj 3666 Making the Grade (排序+dp)
题目链接: Poj 3666 Making the Grade 题目描述: 给出一组数,每个数代表当前位置的地面高度,问把路径修成非递增或者非递减,需要花费的最小代价? 解题思路: 对于修好的路径的每 ...
- POJ - 3666 Making the Grade(dp+离散化)
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- HDU 3666.THE MATRIX PROBLEM 差分约束系统
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- kaungbin_DP S (POJ 3666) Making the Grade
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- POJ 3666 Making the Grade
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- poj 3666 Making the Grade(dp)
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- POJ 3666 Making the Grade (动态规划)
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
随机推荐
- WordPress的神器
导读 Markdown 是一种简单的标记语言,旨在帮助你花费更小的代价来格式化纯文本文档.在 WordPress 下你可以使用 HTML 或者可视化编辑器来格式化你的文档,但是使用 markdown ...
- java软件设计的三层结构
接口: package dao; public interface Dao { String getData(); } package biz; import dao.Dao; public inte ...
- bzoj 2286: [Sdoi2011消耗战
#include<cstdio> #include<iostream> #define M 1000009 #define N 250009 #define ll long l ...
- PowerMock使用遇到的问题——2
如果在测一个类的某一个方法时,这个方法还调用了此类的其他方法,那么如何指定其他方法的返回值呢? Partial mock local private method or public method i ...
- Linux-如何查看登陆shell的类型
输入一个系统不认识的命令(如#ig)获得系统提示 aix/#ig ksh ig not found #echo $ (适用sh/ksh) aix/#echo $ ksh #echo $SHELL(用户 ...
- java获取页面编码
文章出自:http://babyjoycry.javaeye.com/blog/587527 在此感谢原作者...\(^o^)/~ 最近研究抓取网页内容,发现要获取页面的编码格式,Java没有现成 ...
- English idioms
a hot potato : speak of an issue(mostly current) which many people are talking about and which is us ...
- [windows操作系统]windows模块
smss.exe csrss.exe Client/Server Runtime Server Subsystem
- STM32之延时秒,毫秒,微秒
#include "delay.h" #include "stdint.h" #include "stm32f10x.h" ; //us延时 ...
- 04-树5 Complete Binary Search Tree
这题也是第二次做,本想第一次做时参考的算法会和老师讲的一样,不想老师讲的算法用在这题感觉还不如思雪园友的算法(http://www.cnblogs.com/sixue/archive/2015/04. ...