简单DP

/* ***********************************************
Author :Zhou Zhentao
Email :774388357@qq.com
Created Time :2015/11/21 9:45:58
File Name :acm.cpp
************************************************ */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; int mat[+][+];
int flag[+][+];
int dp[+][+];
int n,m; int main()
{
while(~scanf("%d%d",&n,&m)){ for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%d",&mat[i][j]); flag[][]=;
for(int i=;i<m;i++) flag[][i]=abs(-flag[][i-]); for(int i=;i<n;i++)
for(int j=;j<m;j++)
flag[i][j]=abs(-flag[i-][j]); for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(i==&&j==) dp[i][j]=;
if(i==)
{
if(flag[i][j]==)
{
dp[i][j]=dp[i][j-]+mat[i][j]*mat[i][j-];
}
else
{
dp[i][j]=dp[i][j-];
}
}
else if(j==)
{
if(flag[i][j]==)
{
dp[i][j]=dp[i-][j]+mat[i][j]*mat[i-][j];
}
else
{
dp[i][j]=dp[i-][j];
}
}
else
{
if(flag[i][j]==)
{
dp[i][j]=min(dp[i][j-]+mat[i][j]*mat[i][j-],dp[i-][j]+mat[i][j]*mat[i-][j]);
} else
{
dp[i][j]=min(dp[i][j-],dp[i-][j]);
}
}
}
}
printf("%d\n",dp[n-][m-]);
}
return ;
}

HDU 5569 matrix的更多相关文章

  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. (动态规划)matrix -- hdu -- 5569

    http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others)    Memo ...

  4. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  5. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  6. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  7. hdu 2119 Matrix(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others)    ...

  8. HDU 5671 Matrix 水题

    Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...

  9. HDU - 233 Matrix

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5015 解题思路:一看到题目,感觉是杨辉三角形,然后用组合数学做,不过没想出来怎么做,后来看数据+递推思 ...

随机推荐

  1. 一个forward_list C++primer

    #include<iostream> #include<forward_list> using namespace std; int main() { forward_list ...

  2. 在C#中使用反射调用internal的方法

    MSDN上解释Internal如下: The internal keyword is an access modifier for types and type members. Internal t ...

  3. LeetCode OJ 257. Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  4. php之PDO使用【转载】

    <?php $dbh = new PDO('mysql:host=localhost;dbname=access_control', 'root', ''); $dbh->setAttri ...

  5. asp.net html table to DataTable

    添加引用 http://htmlagilitypack.codeplex.com/downloads/get/437941 protected void Export(string content,s ...

  6. linux下MMC/SD/SDIO驱动系列之二 ---- host注册过程(一)

    参考了 http://blog.csdn.net/xieweihua2012/article/details/12844733 在他的基础上更详细的解析源 ...................... ...

  7. CocoaAsyncSocket框架的简单封装

    在iOS开发中使用socket(CFNetwork),一般都是用第三方库AsyncSocket. 参考博客:http://my.oschina.net/worldligang/blog/396881? ...

  8. __declspec(dllexport) 和 __declspec(dllimport)的作用

    operatordll.h #include <iostream> #ifndef _WIN32 #define DLL_EXPORT#else #ifdef OPERATORDLL_EX ...

  9. 1988: Sn 爆long long 的处理方法

    题目描述 给你两个数 n, p(0 < n,p <= 10^15); a1 = 1;  a2 = 1+2;  a3 = 1+2+3;  ... an = 1+2+3+...+n    Sn ...

  10. 128M小内存VPS优化与typecho环境搭建

    在使用Haphost提供的128M内存的VPS建站时,debian7+wordpress+nginx+mysql跑起来相当吃力.然后使用Debian7+typecho+lighttpd+sqlite的 ...