标签:
http://acm.hdu.edu.cn/showproblem.php?pid=5569
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 325 Accepted Submission(s): 196
#include<iostream> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<queue> using namespace std; const int N = 1100; int a[N][N], dp[N][N]; int main() { int n, m, i, j; while(scanf("%d%d", &n, &m)!=EOF) { for(i=1; i<=n; i++) for(j=1; j<=m; j++) scanf("%d", &a[i][j]); memset(dp, 0x3f3f3f3f, sizeof(dp)); for(i=1; i<=n; i++) for(j=1; j<=m; j++) { if(i==1 && j==1) dp[i][j] = 0; else if((i+j)&1) { dp[i][j] = min(dp[i-1][j]+a[i-1][j]*a[i][j], dp[i][j-1]+a[i][j-1]*a[i][j]); } else dp[i][j] = min(dp[i-1][j], dp[i][j-1]); } printf("%d\n", dp[n][m]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/YY56/p/4988538.html