题目连接: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. JPA 系列教程 异常 集锦

    异常1.hibernate升级到3.5版本 异常信息摘要: Associations marked as mappedBy must not define database mappings like ...

  2. redis7--hash set的操作

    数据类型Hash(1)介绍hash数据类型存储的数据与mysql数据库中存储的一条记录极为相似Redis本身就类似于Hash的存储结构,分为key-value键值对,实际上它的Hash数据就好像是在R ...

  3. MVC修改文件上传大小问题

    在web.config文件的system.web节点的httpRuntime节点加入 maxRequestLength="2147483647" executionTimeout= ...

  4. @Scheduled(cron = "0 0 * * * ?")实现定时任务

    //每一个小时执行一次 @Scheduled(cron = "0 0 * * * ?") public void saveDailyScoreScheduled() { try { ...

  5. Ajax的基本请求/响应模型

    一.Ajax工作核心 Ajax的核心是JavaScript对象XMLHttpRequest(简称XHR).它是一种支持异步请求的技术.可以通过使用XHR对象向服务器提出请求并处理响应,而不阻塞用户. ...

  6. openstack私有云布署实践【6 RabbitMQ】

    生产环境建议在集群三台controller上做rabbitmq 使用到队列的openstack组件 OpenStack Compute OpenStack Block Storage OpenStac ...

  7. NYIST OJ 题目42 一笔画问题

    水题.无向图欧拉通路的判定.用并查集判定是不是连通图! #include<cstdio> #include<cstring> #include<cmath> #in ...

  8. Counting Stars

    Counting Stars 题目链接:http://acm.xidian.edu.cn/problem.php?id=1177 离线+一维树状数组 一眼扫过去:平面区间求和,1e6的数据范围,这要h ...

  9. Vanya and Field

    Vanya and Field 题目链接:http://www.codeforces.com/problemset/problem/492/E 逆元 刚看到这题的时候一脸懵逼不知道从哪下手好,于是打表 ...

  10. L2-001. 紧急救援

    L2-001. 紧急救援 题目链接:https://www.patest.cn/contests/gplt/L2-001 Dijstra 本题是dijstra的拓展,在求最短路的同时,增加了不同的最短 ...