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 |
哪位神牛帮我看下我的动归哪儿错了(随便问下,这题可以用动归吧)????一直wrong,谁给我个测试数据啊? 代码如下: #include <iostream> #include <vector> #include <map> #include <algorithm> #include <stdio.h> #include <memory.h> //#include <bitset> using namespace std; struct Road//路径结构体 { int num[5];//选择的票的面值 int maxStamp; }; vector<int> stamp; vector<int> customNeed; vector<bool> need;//对客户需要的面值,提前做标识 vector<vector<int> > typeNum;//typeNum[i][j]表示 vector<vector<bool> > tied;//当前是否tie vector<vector<bool> > answerTied;//以此为结束状态是否tie vector<vector<Road> > road;//保存路径 map<int,int> myMap; int main() { int i,j,k,h,l,a,b,maxNeed,term,temp; while(scanf("%d",&term)!=EOF) { stamp.push_back(term); while(scanf("%d",&term)&&term) { myMap[term]++; if (myMap[term]<4) { stamp.push_back(term); } } sort(stamp.begin(),stamp.end()); need.resize(200); need.assign(need.size(),false); maxNeed=0; while(scanf("%d",&term)&&term) { need[term]=true; if (term>maxNeed) { maxNeed=term; } customNeed.push_back(term); } typeNum.clear(); typeNum.resize(5); typeNum[0].resize(maxNeed+1); typeNum[1].resize(maxNeed+1); typeNum[2].resize(maxNeed+1); typeNum[3].resize(maxNeed+1); typeNum[4].resize(maxNeed+1); tied.clear(); tied.resize(5); tied[0].resize(maxNeed+1); tied[1].resize(maxNeed+1); tied[2].resize(maxNeed+1); tied[3].resize(maxNeed+1); tied[4].resize(maxNeed+1); answerTied.clear(); answerTied.resize(5); answerTied[0].resize(maxNeed+1); answerTied[1].resize(maxNeed+1); answerTied[2].resize(maxNeed+1); answerTied[3].resize(maxNeed+1); answerTied[4].resize(maxNeed+1); road.clear(); road.resize(5); road[0].resize(maxNeed+1); road[1].resize(maxNeed+1); road[2].resize(maxNeed+1); road[3].resize(maxNeed+1); road[4].resize(maxNeed+1); for (j=0;j<5;j++) { typeNum[j].assign(typeNum[j].size(),-1); for (k=0;k<int(road[j].size());k++) { memset(road[j][k].num,0,sizeof(road[j][k].num)); road[j][k].maxStamp=-1; } } typeNum[0][0]=0; tied[0].assign(tied[0].size(),false); answerTied[0].assign(tied[0].size(),false); bool flag; for (j=0;j<int(stamp.size());j++) { for (h=maxNeed;h>0;h--) { for (k=4;k>0;k--) { term=0; if (need[h]) { flag=answerTied[k][h]; } else { flag=tied[k][h]; } temp=typeNum[k][h]; b=road[k][h].maxStamp; for (l=1;l<5;l++) { i=k-l; a=h-l*stamp[j]; if (i<0||a<0) { break; } if(typeNum[i][a]<0) { continue; } if (typeNum[i][a]+1>temp) { flag=false; temp=typeNum[i][a]+1; b=stamp[j]; term=l; } else if(typeNum[i][a]+1==temp) { if (stamp[j]>b) { flag=false; b=stamp[j]; temp=l; } else if(stamp[j]==b) { flag=true; } } } tied[k][h]=flag; if(need[h]) { if (flag) { answerTied[k][h]=true; } else { answerTied[k][h]=tied[k-term][h-term*stamp[j]]; } } if (term>0) { typeNum[k][h]=temp; road[k][h].maxStamp=b; memcpy(road[k][h].num,road[k-term][h-term*stamp[j]].num,sizeof(road[k][h].num)); i=k-term; while(i<k) { road[k][h].num[i++]=stamp[j]; } } } } } for (i=0;i<int(customNeed.size());i++) { term=0; for (j=1;j<5;j++) { if (typeNum[j][customNeed[i]]>typeNum[term][customNeed[i]]) { term=j; } } if (term==0) { printf("%d ---- none\n",customNeed[i]); } else { if (answerTied[term][customNeed[i]]) { printf("%d (%d): tie\n",customNeed[i],typeNum[term][customNeed[i]]); } else { printf("%d (%d):",customNeed[i],typeNum[term][customNeed[i]]); for (j=0;j<term;j++) { printf(" %d",road[term][customNeed[i]].num[j]); } printf("\n"); } } } stamp.clear(); customNeed.clear(); myMap.clear(); need.clear(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator