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

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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<algorithm>
  6. #include<queue>
  7. using namespace std;
  8.  
  9. const int N = ;
  10.  
  11. int a[N][N], dp[N][N];
  12.  
  13. int main()
  14. {
  15. int n, m, i, j;
  16.  
  17. while(scanf("%d%d", &n, &m)!=EOF)
  18. {
  19. for(i=; i<=n; i++)
  20. for(j=; j<=m; j++)
  21. scanf("%d", &a[i][j]);
  22.  
  23. memset(dp, 0x3f3f3f3f, sizeof(dp));
  24.  
  25. for(i=; i<=n; i++)
  26. for(j=; j<=m; j++)
  27. {
  28. if(i== && j==)
  29. dp[i][j] = ;
  30. else if((i+j)&)
  31. {
  32. dp[i][j] = min(dp[i-][j]+a[i-][j]*a[i][j], dp[i][j-]+a[i][j-]*a[i][j]);
  33. }
  34. else
  35. dp[i][j] = min(dp[i-][j], dp[i][j-]);
  36. }
  37.  
  38. printf("%d\n", dp[n][m]);
  39. }
  40. return ;
  41. }

(动态规划)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. ubuntu 无法挂载U盘

    问题描述: usb 1-1: device descriptor read/64,error 18usb 1-1: device descriptor read/64,error 18usb 1-1: ...

  2. Jmeter分布测试

    一.负载机为Linux Linux上安装Jmeter 1.Windows中jmeter整个安装目录copy至Linux /usr/local/autodeploy目录 ps.使用winSCP工具cop ...

  3. 面向服务的架构(SOA)演变图片

    公司项目演变 成熟的公司项目结构 对比 总线-服务的注册与发现

  4. hdu 5418 (Floyd+哈密顿) 飞向世界

    http://acm.hdu.edu.cn/showproblem.php?pid=5418 题目大意是城市的编号是1到n,给出m条路线,表示从a城市飞到b城市飞机要耗多少油,最后问飞机从1出发飞过所 ...

  5. 转~Jenkins pipeline:pipeline 使用之语法详解

    一.引言 Jenkins 2.0的到来,pipline进入了视野,jenkins2.0的核心特性. 也是最适合持续交付的feature. 简单的来说,就是把Jenkins1.0版本中,Project中 ...

  6. Nowcoder OI赛制测试2 F 假的数学题 - 斯特林公式 + 二分

    Description 给定$X$, 找到最小的$N$ 使得$N! > X^X$ 数据范围:  $x <= 1e11$ Solution $X^X$ 太大, 高精也存不过, 所以取对数 : ...

  7. CURLOPT_RETURNTRANSFER

    curl_setopt($ch,CURLOPT_RETURNTRANSFER,);//设置返回值不直接输出,例如返回xml格式,会将xml原样输出

  8. Statement、PreparedStatement、CallableStatement的区别

    此三个接口的声明如下: public interface Statement extends Wrapper, AutoCloseable public interface PreparedState ...

  9. where_1

    (二)WHERE //where不单独使用,与match,optional match,start,with搭配 where 与match,optional match 一起用,表示约束 where ...

  10. IOS 小新兵

    2017-07-02 lipo -info BaiduOAuthSDK.a  查看a文件支持的架构 第一个坎: 报错:  未找到模块baiduLogin对应的类BaiduLoginModule.若是自 ...