| ||||||||||
| 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 | |||||||||
先排序再求与原列的最大公共子序列为什么会WA。。。求高手指教#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int lcs(vector<int> v,vector<int>::iterator ind1,
vector<int>::iterator ind2){
//ind2++;
vector<int>::iterator it1=v.begin(),it2=v.end();
int m=(ind2-ind1)+1,k=(it2-it1)+1;
vector< vector<int> > num;
vector<int> vv(k,0);
for (int i=0;i!=m;++i)
num.push_back(vv);
for(int i=1;i!=m;++i){
for (int j=1;j!=k;++j){
if (ind1[i-1]==it1[j-1])
num[i][j]=1+num[i-1][j-1];
else
num[i][j]=num[i-1][j]>num[i][j-1]?num[i-1][j]:num[i][j-1];
}
}
return num[m-1][k-1];
}
int main(){
vector<int> vec,v;
int next,n;
cin>>n;
for (int i=0;i!=n;++i){
cin>>next;
vec.push_back(next);
}
copy(vec.begin(),vec.end(),back_inserter(v));
sort(v.begin(),v.end());
cout<<lcs(v,vec.begin(),vec.end());
system("pause");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator