dp[a][b][c],表示三个人从小到大依次在a,b。c位置时。距离结束最少的时间。

每次选一个人走到c+1位置搜索就好了。

坑点在于不能floyd。预计题目没说清楚。意思就是假设没送Li,那么Li~n的点连去都不能去。

#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
int dp[31][31][31];
int mp[31][31];
int n;
int dfs(int a[])
{
if(~dp[a[0]][a[1]][a[2]]) return dp[a[0]][a[1]][a[2]];
if(a[2]==n) return 0;
int tmp[3];
int mins=INF;
for(int i=0;i<3;i++)
{
tmp[0]=a[0];tmp[1]=a[1];tmp[2]=a[2];
tmp[i]=a[2]+1;
sort(tmp,tmp+3);
mins=min(mins,dfs(tmp)+mp[a[i]][tmp[2]]);
}
return dp[a[0]][a[1]][a[2]]=mins;
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;i++) mp[i][i]=1;
for(int i=1;i<=n-1;i++)
{
for(int j=i+1;j<=n;j++)
{
scanf("%d",&mp[i][j]);
mp[j][i]=mp[i][j];
}
}
// for(int k=1;k<=n;k++)
// {
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
// }
// }
// }
int a[3]={1,1,1};
printf("%d\n",dfs(a));
}
return 0;
}

poj 1695 Magazine Delivery 记忆化搜索的更多相关文章

  1. POJ 1088 滑雪(记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description ...

  2. POJ 1088 滑雪 DFS 记忆化搜索

    http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...

  3. POJ 1088 滑雪【记忆化搜索】

    题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已 ...

  4. poj 1088 滑雪_记忆化搜索

    题意:略 直接用记忆化搜索就行了 #include<cstdio> #include<iostream> using namespace std; int n,m; int m ...

  5. POJ 3176-Cow Bowling(DP||记忆化搜索)

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14210   Accepted: 9432 Desc ...

  6. HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)

    题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然 ...

  7. POJ 1088 滑雪 【记忆化搜索经典】

    题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:  ...

  8. POJ 3373 Changing Digits 记忆化搜索

    这道题我是看了别人的题解才做出来的.题意和题解分析见原文http://blog.csdn.net/lyy289065406/article/details/6698787 这里写一下自己对题目的理解. ...

  9. poj 1163 The Triangle 记忆化搜索

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44998   Accepted: 27175 De ...

随机推荐

  1. 【整理】用JSON-server模拟REST API

    用JSON-server模拟REST API https://www.cnblogs.com/ys-wuhan/p/6387791.html

  2. QT+ 状态栏+核心控件+浮动窗口

    #include "mainwindow.h" #include <QStatusBar> #include <QLabel> #include<QT ...

  3. github 从一个仓库换到另一个仓库

    1.找到.git目录   2.打开config文件 3.修改仓库地址 4.重新提交 git push --all origin 这样就替我们的项目换仓啦!!!^_^

  4. Must set property 'expression' before attempting to match

    因为这个问题没有直接指向问题的地点, 所以找起来不是很容易. 但是如果找不到, 这个错就会一直都存在. 原因分析: 在使用切面编程的时候, 没有把切入点配置全面 解决方法: 在before, afte ...

  5. Eaton Char-Lynn Motor : Performance Of Small Displacement Motors

    The small-displacement supercharged motor replaces the large-displacement motor with the speed of li ...

  6. Perl中 qw 是 “quoted Word” 或是 “quoted by whitespace”的简写

    Perl中 qw 是 “quoted Word” 或是 “quoted by whitespace”的简写 eg: @strict_pragma = qw ( a b c);

  7. css实现水平/垂直居中效果

    一.如果是已知宽高的元素做水平/垂直居中效果的话,可以直接用具体的数值指定定位布局或偏移布局,这个就不过多讨论.这里主要介绍在不知宽高或需要弹性布局下的几种实现方式. 二.1.table表格法思路:显 ...

  8. jquery实现密码强度检测

    jquery实现密码强度验证   jquery实现密码强度验证 JS代码:   $('#pass').keyup(function(e) { var strongRegex = new RegExp( ...

  9. Xcode导入第三方库图文

    Three20这个与facebook亲戚的开源库是蜚声iPhone开发界,很多App都有它的影子,主要是其真得是功能强大.那么如何将Three20库添加到自己的项目中应用呢?一种是Python命令方式 ...

  10. encodeURI()与decodeURI()等转码方法

    只针对文本编码 encodeURI() 只针对文本解码 decodeURI()针对文本和特殊字符的编码  encodeURIComponent()针对文本和特殊字符的解码  decodeURIComp ...