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……LTE……请路过的建议一个好的剪枝#include<iostream> #include<stack> using namespace std; void dfs(int); int n; int* a; stack<int> s; int count=0; int best_c=0; int main() { cin>>n; int i; a=new int[n]; for(i=0;i<n;i++) { cin>>a[i]; } dfs(0); cout<<best_c<<endl; delete [] a; return 0; } void dfs(int i) { if(i==n) { if(s.size()>best_c) best_c=s.size(); return; } if(s.empty()||a[i]>s.top()) { s.push(a[i]); dfs(i+1); s.pop(); } if(s.size()+n-i-1>best_c) dfs(i+1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator