|
|
вернуться в форумWhy wa #2 This is my program : #include <stdio.h> long a[101][501]={0},f[101][501]={0},h[1000]={0}; short k[101][501]={0}; int main() { long s,i,j,n,m,max=214938364; long min(long,long); scanf("%ld %ld*",&n,&m); for (i=1;i<=n;i++) for (j=1;j<=m;j++) scanf("%ld*",&a[i][j]); for (i=1;i<=m;i++) f[1][i]=a[1][i]; for (i=1;i<=n;i++) f[i][0]=2147383646; for (i=2;i<=n;i++) { for (j=1;j<=m;j++) { f[i][j]=min(f[i-1][j],f[i][j-1])+a[i][j]; if (f[i][j]==f[i-1][j]+a[i][j]) k[i][j]=0; else k[i][j]=-1; } for (j=m-1;j>=1;j--) { f[i][j]=min(f[i][j],f[i][j+1]+a[i][j]); if (f[i][j]==f[i][j+1]+a[i][j]) k[i][j]=1; } } for (i=1;i<=m;i++) if (f[n][i]<max) max=f[n][i],s=i; i=n; h[0]++,h[h[0]]=s; while (i!=1) { if (k[i][s]==1) s++,h[0]++,h[h[0]]=s; if (k[i][s]==-1) s--,h[0]++,h[h[0]]=s; if (k[i][s]==0) i--,h[0]++,h[h[0]]=s; } for (i=h[0];i>=1;i--) printf("%ld ",h[i]); return 0; } long min(long s1,long s2) { if (s1<s2) return s1; else return s2; } Why I wa TEST#2????? Re: Why wa #2 I didn't look at ur code, but I think, I can help u. Try tests like these: 1 10 100 90 80 70 60 50 40 30 20 10 //ans = 10 1 1 1000 //ans = 1 Edited by author 30.06.2009 02:57 |
|
|