matrix

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 509    Accepted Submission(s): 297

Problem Description
Given a matrix with n
rows and m
columns ( n+m
is an odd number ), at first , you begin with the number at top-left corner (1,1) and you want to go to the number at bottom-right corner (n,m). And you must go right or go down every steps. Let the numbers you go through become an array
a1,a2,...,a2k.
The cost is a1∗a2+a3∗a4+...+a2k−1∗a2k.
What is the minimum of the cost?
 
Input
Several test cases(about
5)



For each cases, first come 2 integers, n,m(1≤n≤1000,1≤m≤1000)



N+m is an odd number.



Then follows n
lines with m
numbers ai,j(1≤ai≤100)
 
Output
For each cases, please output an integer in a line as the answer.
 
Sample Input
2 3
1 2 3
2 2 1
2 3
2 2 1
1 2 4
 
Sample Output
4
8
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5589 5588 5587 5586 5585



用dp数组记录下到达每一个点最小的路径

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long dp[1010][1010],num[1010][1010];
int m,n;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(num,0,sizeof(num));
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%lld",&num[i][j]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==1&&j==1)
dp[i][j]=0;
else if((i+j)&1)
{
if(i==1)
dp[i][j]=dp[i][j-1]+num[i][j-1]*num[i][j];
else if(j==1)
dp[i][j]=dp[i-1][j]+num[i-1][j]*num[i][j];
else
dp[i][j]=min(dp[i][j-1]+num[i][j-1]*num[i][j],dp[i-1][j]+num[i-1][j]*num[i][j]);
}
else
{
if(i==1)
dp[i][j]=dp[i][j-1];
else if(j==1)
dp[i][j]=dp[i-1][j];
else dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
}
}
}
printf("%lld\n",dp[n][m]);
}
return 0;
}

hdoj--5569--matrix(动态规划)的更多相关文章

  1. hdu 5569 matrix dp

    matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...

  2. hdu 5569 matrix(简单dp)

    Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...

  3. HDU 5569 matrix

    简单DP /* *********************************************** Author :Zhou Zhentao Email :774388357@qq.com ...

  4. Kruskal HDOJ 4313 Matrix

    题目传送门 题意:如何花最小的代价使得一棵树划分开且不含同类节点 分析:当一条边连接的左右集合同类点小于等于1,那么不用删除,将两个集合合并,要求最小代价,那么贪心思想将权值降序排序,删除后剩下的就是 ...

  5. [Hdoj] Fast Matrix Calculation

    题面:http://acm.hdu.edu.cn/showproblem.php?pid=4965 题解:https://www.zybuluo.com/wsndy-xx/note/1153981

  6. (动态规划)matrix -- hdu -- 5569

    http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others)    Memo ...

  7. hdoj 3376,2686 Matrix Again 【最小费用最大流】

    题目:hdoj 3376 Matrix Again 题意:给出一个m*n的矩阵,然后从左上角到右下角走两次,每次仅仅能向右或者向下,出了末尾点其它仅仅能走一次,不能交叉,每次走到一个格子拿走这个格子中 ...

  8. 【leet-code】542. 01 矩阵

    题目描述 给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离. 两个相邻元素间的距离为 1 . 示例 1: 输入: 0 0 0 0 1 0 0 0 0 输出: 0 0 0 0 1 0 ...

  9. 输入N组父子对,求父子对所组成的二叉树的高度----17年某公司的笔试题

    题目的大致意思如下: 输入N组数,一组数代表一个父子对(如,0 1,0代表父节点,1代表子节点),求这N组数所组成的二叉树的高度: 例如: 输入:6  0 1  0 2  1 3  1 4  2 5 ...

  10. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

随机推荐

  1. 【转载】How to Reset USB Device in Linux

    USB devices are anywhere nowadays, even many embedded devices replace the traditional serial devices ...

  2. easyui datagrid 动态加入、移除editor

    使用easyui 行编辑的时候完毕编辑的功能比較简单,可是假设要依据一个框的值动态改变别的值或者编辑的时候禁用某个框的时候就比較麻烦了. 比方像以下这样:加入行的时候每一个值都是手动输入,改动的时候第 ...

  3. fastjson 的简单使用

    public static void main(String[] args) { /*普通对象与json相互转换*/ User u = new User("miquan", &qu ...

  4. c++变量的作用域、生存期和可见性

    局部变量 范围:在一个函数内部定义的变量,作用范围仅仅限于本函数体内. 生存期:程序运行到本函数才会给局部变量分配内存单元.函数运行完成局部变量所占的存储单元就被释放 全局变量 在函数体外部定义的变量 ...

  5. Find Blank Cell in Excel

    Click Home > Find & Select > Go To Special. In the Go To Special dialog box, check the Bla ...

  6. HOOK劫持自己

    #include <stdio.h> #include <stdlib.h> #include <Windows.h> #include "detours ...

  7. CCS+C6678LE开发记录11:多核协作(IPC)入门

    为更好地发挥C6678的多核性能,需要用到多核协作.幸运的是,我们可以使用官方提供的IPC模块. IPC=Inter-Processor Communication, 核间通信,粗略来说就是多核之间进 ...

  8. HD-ACM算法专攻系列(11)——Exponentiation

    问题描述: 源码: 考察对大数的计算,需要注意去除前导0与后导0. import java.math.BigDecimal; import java.util.*; public class Main ...

  9. (转载) TextView使用一些小技巧

    TextView使用一些小技巧 标签: textviewandroid开发 2015-10-09 16:13 810人阅读 评论(0) 收藏 举报  分类: Android(20)  本文主要讲一些T ...

  10. hiho150周 - 动态规划*

    题目链接 一个n*m的迷宫由‘.’和'b'组成,从(1,1)走到(n,m),只能向右或者向下走,但遇到‘b’时才能改变方向,开始时方向向右. 问到达(n,m)至少改变几个位置上的值 /******** ...