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<iostream> #include<vector> //#include<ctime> using namespace std; class Apple_Catching { public: void input(int,int); void sove(); private: int MAX(int,int); vector<int *> num; vector<int> while_tree; vector<int> v; int T,W; }; int Apple_Catching::MAX(int a,int b) { if(a>b)return a; else return b; } void Apple_Catching::input(int a,int b) { int i,j=0,t,cou=1; //cin>>T>>W; T=a;W=b; while_tree.assign(T,0); v.assign(T,0); //srand ( time(NULL) ); for(i=0;i<T;i++) { cin>>while_tree[i]; //while_tree[i]=rand()%2+1; } t=while_tree[0]; for(i=1;i<T;i++) { if(while_tree[i]==t) { cou++; } else { v[j]=cou; cou=1; t=while_tree[i]; j++; } } v[j]=cou; } void Apple_Catching::sove() { int i,j,N=0; for(i=0;i<T;i++) { if(v[i]!=0)N++; else break; } num.assign(N+1,NULL); for(i=0;i<N+1;i++) { num[i]=new int[W]; } for(i=0;i<=W;i++) { num[0][i]=0; } if(while_tree[0]==1) { for(i=1;i<N+1;i++) { if(i%2!=0) { num[i][0]=num[i-1][0]+v[i-1]; } else { num[i][0]=num[i-1][0]; } } } else { for(i=1;i<N+1;i++) { if(i%2!=0) { num[i][0]=num[i-1][0]; } else { num[i][0]=num[i-1][0]+v[i-1]; } } } for(i=1;i<N+1;i++) for(j=1;j<=W;j++) { num[i][j]=MAX(num[i-1][j],num[i-1][j-1]+v[i-1]); } cout<<num[N][W]<<endl; /*for(i=0;i<N+1;i++) { cout<<v[i]<<' '; } cout<<endl; for(i=0;i<N+1;i++) { cout<<num[i][0]<<' '; } cout<<endl;*/ } int main() { int a,b; while(cin>>a>>b) { Apple_Catching bb; bb.input(a,b); bb.sove(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator