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 |
我用visual c++ 2005可以编译通过,但是提交上去却得到compiler error它这个系统用的是什么c++编译器? 3x, 我的代码如下: #include <iostream> #include <vector> using namespace std; int N; class TrianglePosition { public: TrianglePosition(int x, int y, int v,vector<vector<TrianglePosition>>* triangle):_x(x),_y(y),_v(v),_s(-1),_triangle(triangle){} virtual ~TrianglePosition(); int GetMaxSum(); private: vector<vector<TrianglePosition>>* _triangle; int _x; int _y; int _v; int _s; int max(int a, int b); }; int TrianglePosition::GetMaxSum() { if(_s>-1) return _s; else if(_x>=N-1) { _s=_v; return _s; } else { _s=_v+max(_triangle->at(_x+1).at(_y).GetMaxSum(), _triangle->at(_x+1).at(_y+1).GetMaxSum()); return _s; } } int TrianglePosition::max(int a, int b) { return a>b?a:b; } TrianglePosition::~TrianglePosition() { } int main() { cin>>N; vector<vector<TrianglePosition>> triangle; triangle.reserve(N); for(int i=0;i<N;i++) { vector<TrianglePosition> v; v.reserve(i+1); int tmp; for(int j=0;j<i+1;j++) { cin>>tmp; v.push_back(TrianglePosition(i,j,tmp,&triangle)); } triangle.push_back(v); } int max_sum=triangle[0][0].GetMaxSum(); cout<<max_sum<<endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator