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 ;
}

最新文章

  1. 搭建zookeeper集群
  2. JavaWeb学习总结(五十二)——使用JavaMail创建邮件和发送邮件
  3. RFID-RC522、FM1702SL、M1卡初探
  4. jQuery 获取当前节点的html包含当前节点的方法
  5. Python自动化 【第十四篇】:HTML介绍
  6. 安装好oracle后,打开防火墙遇到的问题!
  7. poj 1833
  8. 【转载】ADO,OLEDB,ODBC,DAO的区别
  9. html+css--水平居中总结-不定宽块状元素方法(三)
  10. 积累的VC编程小技巧之图标、光标及位图
  11. 1724: [Usaco2006 Nov]Fence Repair 切割木板
  12. Java GC - 监控回收行为与日志分析
  13. search a 2D matrix(在二维数组中搜索一个元素)
  14. OpenCV-Python:车道检测
  15. alert执行时机和js线性模型 事件循环
  16. 使用Python下载文件
  17. sshj 示例
  18. 线性空间和异或空间(线性基)bzoj4004贪心+高斯消元优秀模板
  19. 《Redis 垃圾回收》
  20. react-redux 的使用

热门文章

  1. 转 移动端-webkit-user-select:none导致input/textarea输入框无法输入
  2. rem初始化
  3. 3F - Lowest Common Multiple Plus
  4. PAT 1032 挖掘机技术哪家强(20)(有测试样例)
  5. Python之路(第十八篇)shutil 模块、zipfile模块、configparser模块
  6. redis在游戏服务器中的使用初探(三) 信息存储
  7. Android Studio 小新兵
  8. 前端js数据排序
  9. rpm安装jdk7
  10. 粒子跟随本体unity