| ||||||||||
| 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 | |||||||||
有谁帮我看一下?WA#include <iostream>
using namespace std;
int stackx[20000],stacky[20000];
int cost[200][200];
int main(int argc, char* argv[])
{
short n,m,k;
int a[105],b[105],c[105];
while(scanf("%d%d%d",&n,&m,&k))
{
if(n==0&&m==0&&k==0)
break;
for(int i=0;i<k;i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
for(i=0;i<200;i++)
for(int j=0;j<200;j++)
cost[i][j]=0;
int qh=0,qe=1;
stackx[qh]=0;
stacky[qh]=0;
while(qh<qe)
{
for(i=0;i<k;i++)
{
int x=stackx[qh]+a[i];
int y=stacky[qh]+b[i];
if(x>=0&&y>=0&&x<=n&&y<=m&&(cost[x][y]==0||cost[stackx[qh]][stacky[qh]]+c[i]<cost[x][y]))
{
stackx[qe]=x;
stacky[qe]=y;
qe++;
cost[x][y]=cost[stackx[qh]][stacky[qh]]+c[i];
}
}
qh++;
}
if(cost[n][m]==0)
printf("-1\n");
else
printf("%d\n",cost[n][m]);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator