简单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. LeetCode OJ 109. Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  2. mongo细节

    mongo创建表db.createCollection(name, {capped: <Boolean>, autoIndexId: <Boolean>, size: < ...

  3. velocity 教程

    1,<title> $!{product.name} - $!{title} $!{about.title} - $!{title} $!{news.title} - $!{title} ...

  4. 安卓无法生成R文件原因

    原因个人总结出来: 清单文件报错,则无法生成R文件 gen和bin目录可以删除

  5. MPEG1的码流层次与各层次的作用

    1. 序列层(Sequence layer) 序列层主要用于为随机播放提供全局参数支持,这些参数包括图像宽高.像素高宽比.帧率.码率.VBV大小.帧内量化矩阵.帧间量化矩阵. 2. 图像组层(Grou ...

  6. php发送get、post请求获取内容的几种方法

    方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/'; $html = file_get_contents ...

  7. iOS真机测试中出现dyld`dyld_fatal_error错误

    最近进入一家新公司,接手了一个之前由外包公司承接的项目.首先吐槽一下项目质量,哎毕竟也憋了很久了. 1.上手项目是打不开的,所有framework静态库全体飘红,一编译七八十错误.最终是偷懒还是什么就 ...

  8. Echarts自适应浏览器大小

    var myChart = echarts.init(document.getElementById('sitesChar')); var option = { title : { text: 'No ...

  9. Guess the Array

    Guess the Array time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. 贪心<haonan>

    题意: 有一列数,每次在相邻的两个书里面选择一个大数留下,同时ans+大数.问题是,求ans的最小值. 题解: 如果a[i]>a[i-1],那么ans+=a[i]; 如果a[i]>=a[i ...