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. 九度oj 1554 区间问题

    原题链接:http://ac.jobdu.com/problem.php?pid=1554 由数列的前缀和:$\begin{align*}\Large{} S_n &=\Large{}\sum ...

  2. Windows Phone Listbox虚拟化的问题

    最近在项目里面碰到最头疼的一个难题就是Listbox虚拟化的问题,查阅很多文档其实Listbox本身是支持虚拟化的,那么在什么情况下会破坏Listbox的虚拟化呢?目前我接触到的主要有两个原因:一.是 ...

  3. [转]Squid中的日志出现TCP_CLIENT_REFRESH_MISS的问题排除

    转自:http://www.php-oa.com/2008/07/15/tcp_client_refresh_miss.html 今天检查Squid发现大量的日志出现TCP_CLIENT_REFRES ...

  4. CALayer加阴影后动画卡的处理办法

    [self.layer setShadowColor:[UIColor blackColor].CGColor]; [self.layer setShadowOpacity:0.8]; [self.l ...

  5. 自学asp.net mvc(一)

    之前一直做asp.net的webform,现在想学习一下mvc,把自学中遇到的问题记录到博客. 一.codeplex上托管代码 1. 2. 3. 4. 5. 6. 7. 8. 9.

  6. QT实现软件重启

    //重启软件 void MainWindow::on_pushButton_UI_reboot_clicked() { //方式1 需要主函数中事件循环判断 //qApp->exit(773); ...

  7. P1571: [Usaco2009 Open]滑雪课Ski

    DP. ; var t,s,n,i,j,m,l,a,c,d:longint; f,e:array[..,..maxn] of longint; q:array[..] of longint; g:ar ...

  8. pietty and putty safe password

    如何让putty记住密码..pietty也一样的不能记住密码. 找不到好的的方法...只好试着按照参数格式做了一个快捷方式..F:\soft\pietty.exe -pw password123 ro ...

  9. 丢掉 WinPE,使用 DISKPART 来分区吧

    自 Windows Vista 之后的操作系统,如果在安装系统的时候使用 Windows 自带的分区功能,则会多出一个 100M 的系统保留分区.这会让一个物理硬盘,原先最多可以分 4 个主分区的,现 ...

  10. PostgreSQL中的引号和null

    今天工作时写了一个sql,但是PostgreSQL总是提示有语法错误,简单的做个记录:  问题1.'' 和“”单引号和双引号         举个例子: #.select id, delivery_d ...