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. Android中文API-ViewStub

    ViewStub控件是一个不可见,0尺寸得惰性控件.当ViewStub控件设置可见,或者调用inflate(),并运行完毕之后,ViewStub所指定的layout资源就会被载入.这个ViewStub ...

  2. silverlight wpf DataTemplate Command binding

    <Grid x:Name="LayoutRoot" Background="White"> <CommonControl:NoapDataGr ...

  3. mpi之MPI_Sendrecv的用法

    mpi变成常用命令 编译c程序 gcc  例: gcc -Wall -o my_sa my_sa.c  若要编译c++,需要连接, 加参数 gcc -Wall -o my_sa my_sa.cpp - ...

  4. dotnet core test with NUnit

    https://github.com/nunit/dotnet-test-nunit if you are using Visual Studio. Your project.json in your ...

  5. SpringMVC+Spring+Hibernate框架整合原理,作用及使用方法

    转自:https://blog.csdn.net/bieleyang/article/details/77862042 SSM框架是spring MVC ,spring和mybatis框架的整合,是标 ...

  6. [JZOJ NOIP2018模拟10.20 B组]

    T1:原根(math) 题目链接: http://172.16.0.132/senior/#contest/show/2532/0 题目: 题解: 一个数m原根的个数是$\phi{(\phi{(m)} ...

  7. 创建ios界面的三步骤

    1.加载数据 (包括懒加载和字典转模型等) 2.搭建界面 (常见的有九宫格算法和for循环的嵌套等) 3.实现用户交互 (通常用按钮实现)

  8. SAS拆分数据集

    2012年8月8日 主要是根据选取条件来进行拆分 1.根据行数来选: data test; set oldset; if _n_=10 then output; if id="001&quo ...

  9. accept-language

    Chrome: [zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4]Safari: [zh-tw]FF: [zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3 ...

  10. Windows 10 10586 升级