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 ...
随机推荐
- POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <m ...
- sdut 2609 A-Number and B-Number
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609 数位DP 以前没怎么做过,自己憋了半天, ...
- uiwebview 清缓存。,mark
//清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCook ...
- C++-标准输入输出
1,cout 1) 用来向标准输出打印. 2) 如果参数是char*类型,则直接输出字符串.如果想要输出地址,则需要强制转换: <<static_cast<void*>(con ...
- CSU 1111 D(Contest #3)
有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请 ...
- android listview综合使用示例_结合数据库操作和listitem单击长按等事件处理
本示例说明: 1.自定义listview条目样式,自定义listview显示列数的多少,灵活与数据库中字段绑定. 2.实现对DB的增删改查,并且操作后listview自动刷新. 3.响应用户操作点击事 ...
- CCNA 6.9
page 201 show ip route Correction(05-4) Basic configuration of R1: enable configure terminal ...
- 使用Fragment 实现动态UI 和 动态添加Fragment
首先写好每个Fragment: 1.在第一个Fragment写一个按钮,使其加载下一个Fragment 布局: <LinearLayout xmlns:android="http:// ...
- @Param注解在mybatis中的使用以及传入参数的几种方式(转)
第一种: Dao层的方法 <span style="font-size:12px;">Public User selectUser(String name,String ...
- equals() 与 hashcode() 的区别与联系
两者都是从Object类继承的方法,Object中equals方法比较的是this和参数传进来的对象的引用地址是否相同,这样的话,equals返回值为true的必要充分条件就是两者指向同一个对象,那么 ...