题意:

给你一个矩阵,要求从左上角走到右下角,走个的费用: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. 201421123042 《Java程序设计》第12周

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...

  2. Flask 学习 六 大型程序结构

    pip freeze >requirement.txt 自动生成版本号 pip install -r requirement.txt 自动下载对应的库 梳理结构 config.py #!/usr ...

  3. 关于mule中使用jdbc时报No Suitable Driver found错误的问题

    错误大概信息: Exception in thread "main" org.mule.module.launcher.DeploymentStartException: SQLE ...

  4. Python 迭代器之列表解析

     [TOC] 尽管while和for循环能够执行大多数重复性任务, 但是由于序列的迭代需求如此常见和广泛, 以至于Python提供了额外的工具以使其更简单和高效. 迭代器在Python中是以C语言的 ...

  5. 数据恢复培训资料:BMP文件详解

    BMP是一种与硬件设备无关的图像文件格式,使用非常广.它采用位映射存储格式,除了图像深度可选以外,不采用其他任何压缩,因此,BblP文件所占用的空间很大.BMP文件的图像深度可选lbit.4bit.8 ...

  6. 一、Django的基本用法

    学习Django有一段时间了,整理一下,充当笔记. MVC 大部分开发语言中都有MVC框架 MVC框架的核心思想是:解耦 降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用 ...

  7. python使用tesseract-ocr完成验证码识别(安装部分)

    一.tesseract-ocr安装 Ubuntu版本: 1.tesseract-ocr安装 sudo apt-get install tesseract-ocr 2.pytesseract安装 sud ...

  8. JAVA_SE基础——62.String类的构造方法

    下面我先列出初学者目前用到的构造方法 String 的构造方法:     String()  创建一个空内容 的字符串对象.   String(byte[] bytes)  使用一个字节数组构建一个字 ...

  9. LeetCode & Q119-Pascal's Triangle II-Easy

    Description: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3 ...

  10. Python内置函数(58)——input

    英文文档: input([prompt]) If the prompt argument is present, it is written to standard output without a ...