http://acm.hdu.edu.cn/showproblem.php?pid=5569

matrix

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 325    Accepted Submission(s): 196

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

写完这题, 我意识到了动态规划最重要的便是状态转移, 虽然以前听别人说, 但是到底没有自己真正体会到的来的贴切

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

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

  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. 【动态规划】HDU 5492 Find a path (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5492 题目大意: 一个N*M的矩阵,一个人从(1,1)走到(N,M),每次只能向下或向右走.求(N+ ...

  5. 【动态规划】HDU 5781 ATM Mechine

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 题目大意: 一个人有[0,K]内随机的钱,每次可以随意取,但是不知道什么时候取完,取钱超过剩余 ...

  6. 【动态规划】HDU 5791 Two

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5791 题目大意: A,B两个数列,问A的子集和B的子集相等的子集对数.子集内顺序按照数列顺序,相同的 ...

  7. 【动态规划】HDU 1081 & XMU 1031 To the Max

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 http://acm.xmu.edu.cn/JudgeOnline/problem.php?i ...

  8. 动态规划--模板--hdu 1059 Dividing

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. 动态规划之HDU水题

    做水题的感觉真好系列 HDU 2084 数塔 1: 12: 1 23: 1 2 34: 1 2 3 45: 1 2 3 4 5 dp[i][j]第i行第j个数取得的最大值dp[i][j] = max( ...

随机推荐

  1. Linux驱动之LED驱动编写

    从上到下,一个软件系统可以分为:应用程序.操作系统(内核).驱动程序.结构图如下:我们需要做的就是写出open.read.write等驱动层的函数.一个LED驱动的步骤如下: 1.查看原理图,确定需要 ...

  2. C# json解析字符串总是多出双引号

    json好久没用了,今天在用到json的时候,发现对字符串做解析的时候总是多出双引号. 代码如下: string jsonText = "{'name':'test','phone':'18 ...

  3. IIS 域名 带参数 设置重定向

    IIS里面设置重定向后,经常会出现,从百度快照里直接打不开的情况. 可以在IIS里面设置重定向的时候,把参数加上,格式如下: http://www.***.com%S%Q

  4. PHP 语句 函数 字符串处理

    语句: 一:分支语句 1.if(条件1){满足条件1执行} 2.if(条件1){满足条件1执行}else{不满足条件1执行} 3.if(条件1){满足条件1执行}else if(条件2){满足条件2执 ...

  5. dpdk优化相关 转

    注:本文是参照了一些其他文章,原文地址点击这里. 首先根据这篇文章进行了性能瓶颈的分析 策略与方法 首先根据木桶原理,首先要找到最弱的地方,怎么找往上看↑. 想能优化需要考虑如下: 优化BIOS设置 ...

  6. widget jquery 理解

    jquery ui 的所有组件都是基于一个简单,可重用的widget. 这个widget是jquery ui的核心部分,实用它能实现一致的API,创建有状态的插件,而无需关心插件的内部转换. $.wi ...

  7. How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2

    This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e sys cable ...

  8. 洛谷2971 [USACO10HOL]牛的政治Cow Politics

    原题链接 假设只有一个政党,那么这题就退化成求树的直径的问题了,所以我们可以从此联想至\(k\)个政党的情况. 先处理出每个政党的最大深度,然后枚举每个政党的其它点,通过\(LCA\)计算长度取\(\ ...

  9. 如何使用AE来制作烟雾粒子特效

    ​ 1. 首先,我们先建立一个合成,大小1280×720,帧速率25,持续时间为10秒,建好后,再新建一个固态层点击确定. 2.点击效果添加Particular粒子插件 3. 点开粒子插件的发射器,方 ...

  10. 存储过程和函数 PROCEDURE & FUNCTION

    SQL语句执行的时候,要首先编译,然后在被执行.在大型数据库系统中,为了提高效率,将为了完成特定功能的SQL语句集进行编译优化后,存储在数据库服务器中,用户通过指定存储过程的名字来调用执行. 具体而言 ...