hdu5569 matrix
来源:互联网 发布:iphone设置网络权限 编辑:程序博客网 时间:2024/05/22 00:40
思路:dp[i][j]表示到这里的最小和。然后就是分奇偶讨论了。
// #pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <algorithm>#include <iomanip>#include <sstream>#include <string>#include <stack>#include <queue>#include <deque>#include <vector>#include <map>#include <set>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <limits.h>// #define DEBUG#ifdef DEBUG#define debug(...) printf( __VA_ARGS__ )#else#define debug(...)#endif#define MEM(x,y) memset(x, y,sizeof x)using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> ii;const LL inf = 1LL << 60;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;int n, m;int A[1010][1010];int step[110][110];LL dp[1010][1010];int main(){// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);while(scanf("%d%d",&n,&m) != EOF){for (int i = 1;i <= n;++i)for (int j = 1;j <= m;++j)scanf("%d",&A[i][j]);for (int i = 0;i <= n + 1;++i)for (int j = 0;j <= m + 1;++j)dp[i][j] = inf;dp[0][1] = dp[1][0] = 0;dp[1][1] = 0;for (int i = 1;i <= n;++i){for (int j = 1;j <= m;++j){if ((i+j)%2){dp[i][j] = min(dp[i-1][j] + 1LL*A[i-1][j]*A[i][j], dp[i][j]);dp[i][j] = min(dp[i][j-1] + 1LL*A[i][j-1]*A[i][j], dp[i][j]);}else dp[i][j] = min(dp[i][j-1], dp[i-1][j]);}}printf("%lld\n", dp[n][m]);}return 0;}
0 0
- hdu5569 matrix
- HDU5569 matrix(dp)
- hdu5569 matrix(简单dp)
- 【HDU5569 BestCoder Round 63 (div1)B】【DP】matrix 向右走向下走最大乘积和
- hdu5569 dp
- HDU5569(dp)
- hdu5569 RMQ
- HDU5569(动态规划)
- hdu5569/#63 (div.2) 1003
- hdu5569 BestCoder Round #63 (div.2)
- 《Matrix》
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- mAtrix
- [leetcode] 91. Decode Ways 解题报告
- 有关Hibernate映射关系 no session or session was closed问题解绝方法
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 【国外戒色经验第十七期】:国外戒友近400天不撸的秘密
- ios9 http请求不通。修改plist文件也不行的状况
- hdu5569 matrix
- csky elf文件 查看符号表
- UESTC 58 任意阶矩阵的乘法 虽然简单但优化还是要思考一下的 而且也使自己意识到了原来没有注意的问题
- 设计模式之禅-学习笔记 之 第一章:单一职责原则
- UITextField的使用
- CentOS 6.4 上安装 Python 2.7.x
- 给控件添加小图标
- PHP 页面编码声明方法详解(header或meta)
- Hibernate主键