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<stdint.h> #include<iostream> #include<utility> #include<vector> #include<functional> #include<algorithm> std::size_t dp[102][102]={},rd[102][102]={}; int main() { std::ios::sync_with_stdio(false); std::vector<std::pair<uint32_t,std::pair<std::size_t,std::size_t> > > vec; std::size_t r,c; std::cin>>r>>c; vec.reserve(r*c+3); for(std::size_t i(1);i<=r;++i) for(std::size_t j(1);j<=c;++j) { std::cin>>rd[i][j]; vec.push_back(std::make_pair(rd[i][j],std::make_pair(i,j))); } std::sort(vec.begin(),vec.end(),std::greater<std::pair<uint32_t,std::pair<std::size_t,std::size_t> > >()); uint32_t max(0); for(std::vector<std::pair<uint32_t,std::pair<std::size_t,std::size_t> > >::iterator iter(vec.begin());iter!=vec.end();++iter) { if(rd[iter->second.first][iter->second.second]<rd[iter->second.first-1][iter->second.second]) dp[iter->second.first][iter->second.second]=dp[iter->second.first-1][iter->second.second]+1; if(rd[iter->second.first][iter->second.second]<rd[iter->second.first+1][iter->second.second]&&dp[iter->second.first][iter->second.second]<dp[iter->second.first+1][iter->second.second]+1) dp[iter->second.first][iter->second.second]=dp[iter->second.first+1][iter->second.second]+1; if(rd[iter->second.first][iter->second.second]<rd[iter->second.first][iter->second.second-1]&&dp[iter->second.first][iter->second.second]<dp[iter->second.first][iter->second.second-1]+1) dp[iter->second.first][iter->second.second]=dp[iter->second.first][iter->second.second-1]+1; if(rd[iter->second.first][iter->second.second]<rd[iter->second.first][iter->second.second+1]&&dp[iter->second.first][iter->second.second]<dp[iter->second.first][iter->second.second+1]+1) dp[iter->second.first][iter->second.second]=dp[iter->second.first][iter->second.second+1]+1; if(max<dp[iter->second.first][iter->second.second]) max=dp[iter->second.first][iter->second.second]; } std::cout<<max+1<<std::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