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. vue 初识组件

    Vue.component("greeting",{ template: `<p>{{ name }}大家好 <button v-on:click="c ...

  2. 9.10 h5日记

    9.10 1.什么是属性 属性是表示某些事物的一些特征 2.属性分为标签属性和样式属性,二者的区别在于哪里 标签属性:<img src="01.jpg" width=&quo ...

  3. Svn启动窗口报错 Could not load file or assembly 'SharpSvn.dll' or one of its

    win10 64位系统生成没问题,测试都没问题,结果换到win7 64位系统上,点开就出现,网上搜了下,通过以下方式解决, 必须把bin 文件夹全部删除,重新生成.要不还是会报错. Solve it. ...

  4. Android Studio 发布 APK

    打开发布设置窗口 打开Generate Signed APK...窗口,点击Create new... 打开Create New...窗口,创建一个Key,这个Key的相关信息一定要好好保存,因为以后 ...

  5. Win7自带功能,刻录光盘遇到的问题

    Win7系统的可以使用系统自带有光盘刻录功能来刻录光盘. 把一张空白光盘放入刻录机,打开“计算机”窗口,双击刻录机图标,弹出“刻录光盘”对话框,选择刻录类型.这里有两个选项:一个是“类似于USB闪存驱 ...

  6. elasticsearch权威指南

    elasticsearch权威指南 https://elasticsearch.cn/book/elasticsearch_definitive_guide_2.x/

  7. 0 or 1,1 and 0

    最近小编遇到很头疼的的一件事 就是以下这几道运算题 ,以下结果是小编经过大量的运算得出的 一.或运算 1.0 or 1 结果为:1 2.1 or 0 结果为:1 3.1 or 2 结果为:1 4.2 ...

  8. MySQL学习笔记-事务相关话题

    事务机制 事务(Transaction)是数据库区别于文件系统的重要特性之一.事务会把数据库从一种一致状态转换为另一个种一致状态.在数据库提交工作时,可以确保其要么所有修改都已经保存了,要么所有修改都 ...

  9. Centos7 开启vsftpd

    Centos 1.开启DNS 可yum install (操作后要关闭) # vi /etc/resolv.conf# (INSERT)nameserver 8.8.8.8# (INSERT)表示按I ...

  10. Linux学习笔记:Jenkins安装

    操作系统是CentOS 7,安装Jenkins 首先安装jdk,可在Oracle jdk和Openjdk中任选其一安装Oracle jdk步骤见:   https://www.cnblogs.com/ ...