POJ 3666 Making the Grade
来源:互联网 发布:mysql 用户登录失败 编辑:程序博客网 时间:2024/06/05 09:26
刚开始想到要把结果作为状态,但a[i]的取值范围太大,所以一直没想出来,然后搜了个解题报告,看到要离散化,于是又回来想。
最后设了个自己都不太确定思路有没有问题的状态,抱着试一试的心态提交上去,然后就A了,也是醉了
dp[i][j]:前i个数,前j个高度的最小值
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;const int inf=2000000000;int n,a[2005],dp[2005][2005],y[2005];//dp[i][j]:前i个数,前j个高度的最小值 void init(){for(int i=0;i<=n;i++){for(int j=0;j<=n;j++){dp[i][j]=inf;}}for(int i=1;i<=n;i++) dp[0][i]=0;}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endifscanf("%d",&n);for(int i=1;i<=n;i++) {scanf("%d",&a[i]);y[i]=a[i];}sort(y+1,y+n+1);init();for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){dp[i][j]=min(dp[i-1][j]+abs(a[i]-y[j]),dp[i][j-1]); }}int ans=inf;for(int i=1;i<=n;i++) ans=min(dp[n][i],ans);printf("%d\n",ans);}
0 0
- POJ 3666 Making the Grade
- POJ 3666 Making the Grade
- POJ 3666 Making the Grade
- poj 3666--Making the Grade
- POJ 3666 Making the Grade
- poj 3666 Making the Grade
- POJ 3666 Making the Grade
- POJ 3666 Making the Grade
- POJ 3666 Making the Grade
- POJ-3666 Making the Grade
- POJ-3666 Making the Grade
- poj 3666 Making the Grade
- POJ 3666 Making the Grade
- POJ 3666 Making the Grade [DP]
- POJ 3666 Making the Grade(左偏树)
- POJ 3666 Making the Grade (dp)
- poj 3666 Making the Grade (动态规划)
- 【POJ 3666】Making the Grade(简单DP)
- 我们依旧在追梦的路上-山东省第六届ACM比赛总结
- POJ 3041 Asteroids
- 急救常识读书笔记-3
- Deluanary三角细分及voronoi图绘制的Opencv实现(未完待续)
- Android APK反编译
- POJ 3666 Making the Grade
- 在oracle官方网站上的Windows Server System Technology Center 网址
- node.js 创建 https 服务器
- 网页重构——bigpipe中的页面构建优化
- 《剑指Offer》学习笔记--面试题34:丑数
- HTML5 开发工具
- joomla 开发的最佳实践
- 线索二叉树
- CornerStone上传静态库(.a文件)