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 (,) 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 isa1∗a2+a3∗a4+...+a2k−∗a2k. What is the minimum of the cost?
 
Input
Several test cases(about )

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

N+m is an odd number.

Then follows n lines with m numbers ai,j(≤ai≤)

 
Output
For each cases, please output an integer in a line as the answer.
 
Sample Input

 
Sample Output

 
Source

令dp[i][j]表示当前走到第i,j个位置的最小贡献,初始化做好了,然后根据i+j是奇数偶数的情况分别计算dp即可,最后要用long long。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1006
#define inf 1<<29
ll n,m;
ll mp[N][N];
ll dp[N][N];
int main()
{
while(scanf("%I64d%I64d",&n,&m)==){
memset(dp,,sizeof(dp));
for(ll i=;i<=n;i++){
for(ll j=;j<=m;j++){
scanf("%I64d",&mp[i][j]);
}
}
for(ll i=;i<=n+;i++){
dp[i][]=inf;
mp[i][]=inf;
}
for(ll i=;i<=m+;i++){
dp[][i]=inf;
mp[][i]=inf;
} dp[][]=mp[][];
dp[][]=mp[][]*mp[][];
dp[][]=mp[][]*mp[][];
for(ll i=;i<=n;i++){
for(ll j=;j<=m;j++){
if(i== && j==) continue;
if(i== && j==) continue;
if(i== && j==) continue;
if((i+j)%==){
dp[i][j]=min(dp[i-][j],dp[i][j-]);
//printf("i , j %d %d %d\n",i,j,dp[i][j]);
}
else{
dp[i][j]=min(dp[i-][j]+mp[i-][j]*mp[i][j],dp[i][j-]+mp[i][j-]*mp[i][j]);
//printf("i , j %d %d %d\n",i,j,dp[i][j]);
} }
} printf("%I64d\n",dp[n][m]);
}
return ;
}

hdu 5569 matrix(简单dp)的更多相关文章

  1. HDU 5569 matrix

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

  2. hdu 5569 matrix dp

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

  3. HDU 2686 Matrix 多线程dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 思路:多线程dp,参考51Nod 1084:http://www.51nod.com/onlin ...

  4. hdu 4576 (简单dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...

  5. HDU 2836 Traversal 简单DP + 树状数组

    题意:给你一个序列,问相邻两数高度差绝对值小于等于H的子序列有多少个. dp[i]表示以i为结尾的子序列有多少,易知状态转移方程为:dp[i] = sum( dp[j] ) + 1;( abs( he ...

  6. HDU 4313 Matrix 树形dp

    题意: 给定n个点的树,m个黑点 以下n-1行给出边和删除这条边的费用 以下m个黑点的点标[0,n-1] 删除一些边使得随意2个黑点都不连通. 问删除的最小花费. 思路: 树形dp 每一个点有2个状态 ...

  7. hdu 2128 Frog(简单DP)

    Frog Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

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

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

  9. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

随机推荐

  1. TCP/IP协议详解概述

    TCP/IP协议详解卷1--第一章概述--读书笔记 作者:vpoet 日期:2015/06/25 注:本系列的文章只是作者对TCP/IP协议的理解,难免会出现纰漏或者不完整,当然也有可能很肤浅,希望大 ...

  2. ZOJ3516 (图的遍历)

    Tree of Three Time Limit: 2 Seconds      Memory Limit: 65536 KB Now we have a tree and some queries ...

  3. C pointers

    指向整型数组指针int (*p)[10] = matrix;增加这个指针的值使它指向下一个整型数组 指向整型指针int *pi = &matrix[0][0];int *pi = &m ...

  4. Android专项面试训练题(一)

    1.下面不可以退出Activity的是?(D) A.finish() B.抛异常强制退出 C.System.exit(0) D.onStop() 解析: A, finish() 方法就是退出activ ...

  5. Vue.js快速入门

    Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得我们 ...

  6. Android应用开发中webview上传文件的几种思路

    1. 常规方法,重写WebChromeClient 的 openFileChooser 方法 private class MyWebChromeClient extends WebChromeClie ...

  7. Carmack在QUAKE3中使用的计算平方根的函数

    // // Carmack在QUAKE3中使用的计算平方根的函数 // float CarmSqrt(float x){ union{ int intPart; float floatPart; } ...

  8. 80端口被NT kernel & System 占用pid= 4的解决方法

    引用http://www.2cto.com/os/201111/111269.html的方法.亲测可用 该进程是Http.sys.它是http API的驱动组件,Http栈服务器.如果该端口被Http ...

  9. resolv.conf 是什么

    From Wikipedia, the free encyclopedia This article does not cite any references or sources. Please h ...

  10. Asp.net MVC razor语法参考

    Razor语法的快捷参考http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/ 只是copy下来便于查阅! I ...