标签:des style blog http color io os ar java
Time Limit: 300/100 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1642 Accepted Submission(s): 807
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> using namespace std; const int MAXN=20+5; int num[MAXN][MAXN],dp[MAXN][MAXN]; int main() { int n,k; while(scanf("%d %d",&n,&k)!=EOF) { memset(dp,0,sizeof(dp)); memset(num,0,sizeof(num)); for(int i=0;i<n;i++) for(int j=0;j<k;j++) scanf("%d",&num[i][j]); for(int i=1;i<n;i++) for(int j=0;j<k;j++) for(int l=0;l<k;l++) { if(l==0) dp[i][j]=dp[i-1][l]+(abs(num[i-1][l]-num[i][j])); else dp[i][j]=min(dp[i-1][l]+abs(num[i-1][l]-num[i][j]),dp[i][j]); } int minn=0x3f3f3f3f; for(int i=0;i<k;i++) if(dp[n-1][i]<minn) minn=dp[n-1][i]; printf("%d\n",minn); } return 0; }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/clliff/p/4029577.html