Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求高人指点一二#include<iomanip.h> #include<stdio.h> struct node { int v; char ch; }map[200][900]; int value[200][900]; int temp[9000]; int min=1000000000; int main() { int m,n,i,j,k,tmp,k1,k2,k3; scanf("%d%d",&m,&n); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&value[i][j]); } } for(i=1;i<=n;i++) { map[1][i].v=value[1][i]; map[1][i].ch='n';map[m][i].ch='u'; } for(i=2;i<m;i++) { for(j=1;j<=n;j++) { min=1000000000; tmp=0; for(k=1;k<j;k++) { tmp+=map[i-1][k].v; for(k1=k;k1<j;k1++) { tmp+=value[i][k1]; } if(tmp<min) { k3=k; min=tmp; } tmp=0; } for(k=n;k>j;k--) { tmp+=map[i-1][k].v; for(k2=k;k2>j;k2--) { tmp+=value[i][k2]; } if(tmp<min) { k3=k; min=tmp; } tmp=0; } tmp=map[i-1][j].v; if(tmp<=min) { k3=j; min=tmp; } map[i][j].v=min+value[i][j]; if(k3<j)map[i][j].ch='l'; if(k3==j)map[i][j].ch='u'; if(k3>j) { // map[i][j].ch='r'; map[i][j++].ch='r'; for(;j<k3;j++) { map[i][j].ch='r'; map[i][j].v=min; min=min-value[i][j]; } map[i][j].ch='u'; map[i][j].v=min; } min=1000000000; } } for(i=1;i<=n;i++) { if(map[m][i].v<min) { min=map[3][i].v; k=i; } } i=m;j=k;k3=0; while(map[i][j].ch!='n') { temp[k3++]=j; if(map[i][j].ch=='u')i--;else if(map[i][j].ch=='l')j--;else if(map[i][j].ch=='r')j++; } printf("%d\n",j); for(i=k3-1;i>=0;i--) { printf("%d\n",temp[i]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator