hdu 5569(dp)
来源:互联网 发布:沪昆高铁偷工减料知乎 编辑:程序博客网 时间:2024/06/05 19:26
matrix
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 450 Accepted Submission(s): 270
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 followsn lines with m numbers ai,j(1≤ai≤100)
For each cases, first come 2 integers,
N+m is an odd number.
Then follows
Output
For each cases, please output an integer in a line as the answer.
Sample Input
2 31 2 32 2 12 32 2 11 2 4
Sample Output
48
#include <bits/stdc++.h>using namespace std;#define inf (1<<30)__int64 a[1005][1005];int dp[1005][1005];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) for(int k=1;k<=m;k++) scanf("%I64d",&a[i][k]); dp[0][0]=dp[1][0]=dp[0][1]=0; a[0][0]=a[1][0]=a[0][1]=inf; for(int i=2;i<=n;i++)dp[i][0]=a[i][0]=inf; for(int k=2;k<=m;k++)dp[0][k]=a[0][k]=inf; for(int i=1;i<=n;i++) for(int k=1;k<=m;k++) if((i+k)%2==0) dp[i][k]=min(dp[i-1][k],dp[i][k-1]); else dp[i][k]=min(dp[i-1][k]+a[i-1][k]*a[i][k],dp[i][k-1]+a[i][k-1]*a[i][k]); printf("%d\n",dp[n][m]); } return 0;}
0 0
- hdu 5569 简单dp
- HDU 5569 matrix(DP)
- hdu 5569 matrix(dp)
- hdu-5569-matrix-dp
- hdu 5569(dp)
- hdu 5569 DP
- hdu 5569 matrix【dp】
- HDU-5569 matrix(DP)
- hdu 5569 matrix (dp)
- hdu 5569 matrix(dp)
- hdu 5569(二维dp,水题)
- HDU DP
- DP? HDU
- DP? HDU
- DP? HDU
- 【dp】HDU
- 【dp】HDU
- 【dp】 HDU
- hdu 5567
- 使用python对url编码解码
- 关系型数据库的理解
- 签到题
- 解决virtualbox只能安装32bit的问题
- hdu 5569(dp)
- Nim GameMy
- qml实现简单记事本程序
- Codeforces Round #333 Lipshitz Sequence 优先队列
- Java之Jacob调用COM接口DLL-----------------------------------dm。dll
- 跨浏览器的事件对象
- 真·为WordPress添加自机LaTeX支持(LaTeX for WordPress+MathJax)
- Linux僵尸进程
- hibernate学习笔记(一)hibernate应用背景(为什么要用hibernate)