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 |
我的这个dfs测了好几组bt的数据都没有错误,但是一直wa着,那位帮着看看!#include <iostream> #include <cmath> using namespace std; void gui(int i,int tot,int ma,int mi); int xian; int m,n; int mon[105]={0},le[105]={0},ti[105]={0}; int xiang[105][105][2]={0},xiao[105]={0}; int main() { for (int i=1;i<=100;i++) xiao[i]=10000; scanf("%d%d",&m,&n); for (int i=1;i<=n;i++) { scanf("%d%d%d",&mon[i],&le[i],&ti[i]); xiao[i]=mon[i]; for (int j=1;j<=ti[i];j++) { scanf("%d%d",&xiang[i][j][0],&xiang[i][j][1]); if (xiang[i][j][1]<xiao[i]) xiao[i]=xiang[i][j][1]; } } xian=mon[1]; for (int i=1;i<=ti[1];i++) gui(xiang[1][i][0],xiang[1][i][1],le[1],le[1]); printf("%d\n",xian); // system("pause"); return 0; } void gui(int i,int tot,int ma,int mi) { if (le[i]<mi) mi=le[i]; if (le[i]>ma) ma=le[i]; // printf("%d %d %d %d\n",i,tot,ma,mi); if (tot+mon[i]<xian) { xian=tot+mon[i]; // printf("%d\n",xian); // system("pause"); } for (int j=1;j<=ti[i];j++) if (abs(le[xiang[i][j][0]]-ma)<=m&&abs(le[xiang[i][j][0]]-mi)<=m) if (tot+xiao[xiang[i][j][0]]<xian) gui(xiang[i][j][0],tot+xiang[i][j][1],ma,mi); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator