题意:

给你一个矩阵,要求从左上角走到右下角,走个的费用:a[1]*a[2] + a[3]*a[4] + ......+ a[2n-1]*a[2n]

思路:

果然不机智,自己把自己套路了

对于每个奇数点,如下图的有下角的点它便可由3个值为2的点到达,具体画图便知。

所以我们可以用类似dp的方法,找出每个点的奇数点最优解,注意下边界即可

1 1 1 2

1 1 2 1

1 2 1 1

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
ll a[1005][1005]; int main()
{
int n,m;
while(scanf("%d%d",&n,&m) != EOF)
{
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
scanf("%I64d",&a[i][j]);
}
a[1][2] *= a[1][1];
a[2][1] *= a[1][1];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if((i+j)%2)
{
int t1,t2,t3;
t1 = t2 = t3 = inf;
if(j > 2)
t1 = a[i][j-2]+a[i][j]*a[i][j-1];
if(i > 1 && j > 1)
t2 = a[i-1][j-1]+min(a[i][j]*a[i-1][j],a[i][j]*a[i][j-1]);
if(i > 2)
t3 = a[i-2][j]+a[i-1][j]*a[i][j];
t1 = min(t1,t2);
t1 = min(t1,t3);
if(t1 >= inf)
continue;
a[i][j] = t1;
}
}
printf("%I64d\n",a[n][m]);
}
return 0;
}

  

hdu5569 BestCoder Round #63 (div.2)的更多相关文章

  1. HDU5569/BestCoder Round #63 (div.2) C.matrix DP

    matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...

  2. BestCoder Round #63 (div.2)

    感觉有些无聊的比赛. A 暴力枚举下就行 B 简单的dp,但是wa了一发后就去先把C做了,然后发现如果输入的100个数,是如1,2,3,4,...,100,然后k=50,个数为c(100,50).果断 ...

  3. HDU5568/BestCoder Round #63 (div.2) B.sequence2 dp+高精度

    sequence2 Problem Description Given an integer array bi with a length of n, please tell me how many ...

  4. HDU5567/BestCoder Round #63 (div.2) A sequence1 水

    sequence1  Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for a ...

  5. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  6. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  7. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  9. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. vue style width a href动态拼接问题 ?

    style width 这个问题 折磨了我一个上午了  好惭愧 因为项目涉及到 进度条 所以必须用行内样式  style 用过vue的都知道 vue中style的用法 大众用法 :style=&quo ...

  2. 【技巧】Java工程中的Debug信息分级输出接口及部署模式

    也许本文的标题你们没咋看懂.但是,本文将带大家领略输出调试的威力. 灵感来源 说到灵感,其实是源于笔者在修复服务器的ssh故障时的一个发现. 这个学期初,同袍(容我来一波广告产品页面,同袍官网)原服务 ...

  3. java截取一个字符串正数或倒数某个特定字符前后的内容

    取出正数第二个“.”后面的内容 public class TestCode { public static void main(String[] args) { String str ="2 ...

  4. Microsoft Soft SQL Server 大数据----分区表性能测试

    分区表 MSSQL有一个大数据储存方案,可以提高效率那就是分区表. 使用起来跟普通表没有区别.至于具体原理自己度娘吧. 真正性能的提高,是依赖于硬件的加入.也是就说,当把一个表设置成分区表,每一个分区 ...

  5. Mysql编译安装详解

    wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz root@Mysql-server ~]# yum install -y c ...

  6. SpringCloud的服务注册中心(四)- 高可用服务注册中心的搭建

    一.双 服务注册注册中心 1.服务注册中心的服务端 - EurekaServer 1.1.EurekaServer1 String.application.name=eureka-server ser ...

  7. maven常见问题处理(3-3)Gradle编译时下载依赖失败解决方法

    Gradle编译时在本地仓库中如果没有发现依赖,就会从远程仓库中下载, 默认的远程仓库为 mavenCentral(),即 http://repo1.maven.org/maven2/往往访问速度特别 ...

  8. OAuth2.0学习(1-4)授权方式1-授权码模式(authorization code)

    参与者列表: (1) Third-party application:第三方应用程序,又称客户端(client),如:"云冲印".社交应用. (2)HTTP service:HTT ...

  9. Django知识总结

    一.什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. web应 ...

  10. uva 10870

    https://vjudge.net/problem/UVA-10870 题意: f(n) = a1f(n − 1) + a2f(n − 2) + a3f(n − 3) + . . . + adf(n ...