题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4824

题意:中文,不解释

题解:双调欧几里德旅行商问题,具体可看dp双调欧几里德旅行商,这里注意的是起点为0,0。

 #include<cstdio>
#define FFC(i,a,b) for(int i=a;i<=b;i++)
const int maxn=,inf=1e9;
int dp[maxn][maxn],t,n;
struct node{int x,y;}g[maxn];
int abs(int a){return a>?a:-a;}
int Min(int a,int b){return a>b?b:a;}
int dis(int i,int j){
int s1=abs(g[i].x-g[j].x)*+abs(g[i].y-g[j].y),s2;
int max=g[i].y>g[j].y?g[i].y:g[j].y,min=Min(g[i].y,g[j].y);
s2=abs(g[i].x-g[j].x)*+-max+min;
return s1>s2?s2:s1;
}
int fuck(int n){
FFC(i,,n)dp[i][i-]=inf;
dp[][]=,dp[][]=dis(,);
FFC(i,,n)FFC(j,,i-)
dp[i][j]=dp[i-][j]+dis(i-,i),dp[i][i-]=Min(dp[i][i-],dp[i-][j]+dis(j,i));
return dp[n][n-]+dis(n,n-);
}
int main(){
scanf("%d",&t);
g[].x=g[].y=;
while(t--){
scanf("%d",&n);
FFC(i,,n+)scanf("%d%d",&g[i].x,&g[i].y);
printf("%d\n",fuck(n+)+n*);
}
return ;
}

hdu_4824_Disk Schedule(dp)的更多相关文章

  1. Codeforces 1324E Sleeping Schedule DP

    题意 给你一个长度为\(n\)的数组\(a\)和3个数字\(h,l和r\).\(t\)初始为0,每次可以使\(t=(t+a_i) \% h\)或者\(t=(t+a_i-1)\%h\),如果这时\(t\ ...

  2. 2014百度之星第二题Disk Schedule(双调欧几里得旅行商问题+DP)

    Disk Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  3. HDU 4175 Class Schedule (暴力+一点dp)

    pid=4175">HDU 4175 题意:有C座楼,每座楼有T个教室.一个人须要訪问C个教室.每座楼仅仅能訪问一个教室. 訪问教室须要消耗能量,从x点走到y点须要消耗abs(x-y) ...

  4. 【dp】Arrange the Schedule

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3538 题意:如题. 题解: 假如 一组数据 ...(n1)A.. ...

  5. UVA - 1025 A Spy in the Metro[DP DAG]

    UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...

  6. UVA1025---A Spy in the Metro(DP)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 Secret agent Maria was sent to Alg ...

  7. 百度之星资格赛——Disk Schedule(双调旅行商问题)

    Disk Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  8. 【UVA 1380】 A Scheduling Problem (树形DP)

    A Scheduling Problem   Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...

  9. poj 3616 Milking Time(dp)

    Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...

随机推荐

  1. iOS7之后的文本高度封装

    #import "NSString+Util.h" @implementation NSString (Util) +(CGFloat)changeStationWidth:(NS ...

  2. Java代码之输出参数和(强制类型转换)

    说明(因为Java中java Application的参数都是默认的字符型的数据,所以需要强制类型转换这一步骤) 设计思想: 向系统里输入若干个参数,计算出参数个数,利用for语句计算出参数的和.(程 ...

  3. windows线程池四种情形(win核心读书笔记)

    windows线程池四种情形(win核心读书笔记) Mircosoft从Windows2000引入线程池API,并在Vista后对线程池重新构架,引入新的线程池API.以下所有线程池函数均适用于Vis ...

  4. zoj 1586 QS Network

    最小生成树,刚刚学了Prim算法. 对每条边变的权值进行预处理,c[i][j] = c[i][j] + p[i] + p[j] 其中c[i][j]为输入的权值,p[i],p[j]为连接这两个节点所需的 ...

  5. mysql 初始化修改密码问题(Mac系统)

    今天公司大牛帮我搞定了mysql初始化密码问题,纪录一下: ~ ps aux | grep mysqlMetro 7149 0.0 0.0 2432772 564 s000 R+ 7:16下午 0:0 ...

  6. Ubuntu系统上安装搜狗拼音输入法sogou

    1. 首先在百度搜索搜狗拼音输入法Linux就能看到它的官网:http://pinyin.sogou.com/linux/ 下载后直接安装.安装成功后在控制台输入 im-config 如果选中的是fc ...

  7. 利用Fiddler抓取websocket包

    一.利用fiddler抓取websockt包 打开Fiddler,点开菜单栏的Rules,选择Customize Rules... 这时会打开CustomRules.js文件,在class Handl ...

  8. iOS开发自定义流水布局

    //集成UICollectionViewFlowLayout 自己写的布局 //  SJBFlowLayout.m //  自定义流水布局 // //  Created by zyyt on 16/7 ...

  9. 帝国cms

    1:帝国cms 设置安装完成 2: 帝国cms 封面页模板 内容页模板和列表页模板完成

  10. bootcss

    道友们,今天由贫道讲一下bootcss的编码规范: 首先黄金定律:一个项目一定要有一套编码规范,无伦项目有多少人参与都要一致. 用两个空格来代替制表符(tab) -- 这是唯一能保证在所有环境下获得一 ...