matrix

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
 
题解:令dp[i][j]dp[i][j]表示当前走到第i,ji,j个位置的最小贡献,我们可以假定(i+j)(i+j)为奇数,由该状态可以转移向最多44个位置,就可以了。
 

///
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define meminf(a) memset(a,127,sizeof(a)); inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 100000+50
#define mod 1000000007
#define inf 1000000007 ll a[][],b[maxn],k,dp[][],l[maxn],r[maxn],ans[maxn],D[maxn],n,m;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++) {
for(int j=;j<=m;j++) {
scanf("%I64d",&a[i][j]);dp[i][j]=inf;
}
}
dp[][]=;
for(int i=;i<=n;i++) {
for(int j=;j<=n;j++) {
if(i==&&j==) {
dp[i][j+]=min(dp[i][j]+a[i][j]*a[i][j+],dp[i][j+]);
dp[i+][j] =min( dp[i][j]+a[i][j]*a[i+][j],dp[i+][j]);
}
else {
dp[i][j+]=min(dp[i][j]+a[i][j+]*a[i][j+],dp[i][j+]);
dp[i+][j] =min( dp[i][j]+a[i+][j]*a[i+][j],dp[i+][j]);
dp[i+][j+]=min(dp[i][j]+a[i+][j]*a[i+][j+],dp[i+][j+]);
dp[i+][j+] =min( dp[i][j]+a[i][j+]*a[i+][j+],dp[i+][j+]);
}
}
} cout<<dp[n][m]<<endl; } return ;
}

HDU5569/BestCoder Round #63 (div.2) C.matrix DP的更多相关文章

  1. hdu5569 BestCoder Round #63 (div.2)

    题意: 给你一个矩阵,要求从左上角走到右下角,走个的费用:a[1]*a[2] + a[3]*a[4] + ......+ a[2n-1]*a[2n] 思路: 果然不机智,自己把自己套路了 对于每个奇数 ...

  2. HDU5568/BestCoder Round #63 (div.2) B.sequence2 dp+高精度

    sequence2 Problem Description Given an integer array bi with a length of n, please tell me how many ...

  3. BestCoder Round #63 (div.2)

    感觉有些无聊的比赛. A 暴力枚举下就行 B 简单的dp,但是wa了一发后就去先把C做了,然后发现如果输入的100个数,是如1,2,3,4,...,100,然后k=50,个数为c(100,50).果断 ...

  4. BestCoder Round #81 (div.2) B Matrix

    B题...水题,记录当前行是由原矩阵哪行变来的. #include<cstdio> #include<cstring> #include<cstdlib> #inc ...

  5. HDU5567/BestCoder Round #63 (div.2) A sequence1 水

    sequence1  Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for a ...

  6. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  7. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  8. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

随机推荐

  1. 用js进行日期的加减

    如题,开始查了查js的使用文档,但没发现可以直接用的函数,于是就想自己写函数来着,这就要涉及到每个月天数的判断,如果是2月份的话,还要涉及到闰年的判断,虽然不复杂但我想js应该不会这么低级,于是查了下 ...

  2. MYSQL与 R

    1. 配置MySQL ODBC必须先安装MySQL ODBC driver下载地址可以为:http://www.mysql.com/downloads/connector/odbc/ 2. 控制面板\ ...

  3. C#的winform矩阵简单运算

    C#的winform矩阵简单运算 程序截图 关键代码 using System; using System.Collections.Generic; using System.ComponentMod ...

  4. Ant学习---第四节:Ant属性的介绍

    一.ant 属性设置,用 property 标签,详解如下: 特点 大小写敏感: 不可改变,先到先得,谁先设定,之后的都不能改变. 设置 1 .设置 name 和 value 属性值,比如: < ...

  5. haproxy实现mysql从库负载均衡

    本文主要讲述通过haproxy实现mysql从库间的负载均衡,至于mysql主从的搭建,本文不再重述,可以参考我之前写的博客. 1.首先下载haproxy包 wget http://haproxy.1 ...

  6. js数组排序

    在JS中,sort方法可用于数组的排序:先来看一个例子: var arr = [1, 2, 3, 5, 7, 78, 8, 89]; arr.sort(); console.log(arr); // ...

  7. Kibana4学习<二>

    生产环境部署 Kibana4 是是一个完整的 web 应用.使用时,你需要做的只是打开浏览器,然后输入你运行 Kibana 的机器地址然后加上端口号.比如说:localhost:5601 或者 htt ...

  8. VC6.0装了visual assist x回车键不能补全代码的解决方法

    问题:VC6.0装了visual assist x补全代码具体怎么用?         输入字母后会像输入法那样出现一个菜单        但是怎么选择菜单里面的内容呢?        什么 回车  ...

  9. Retry Pattern

    Retry Pattern https://msdn.microsoft.com/en-us/library/dn589788.aspx https://msdn.microsoft.com/en-u ...

  10. 【Ubuntu】NAT配置

    1.简介 2.配置 1.简介 NAT(Network Address Translation,网络地址转换)是将IP 数据包头中的IP 地址转换为另一个IP 地址的过程.在实际应用中,NAT 主要用于 ...