Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- int *a = new int [n+2];
- a[0]=INT_MIN;
- a[n+1]=INT_MAX;
- for(int i=1;i<=n;i++) cin>>a[i];
- int dp[n+2]={0};
- dp[0]=1; dp[1]=1;
- int F[n+2]={0};
- int vet[n+2];
- vet[1]=0;
- F[0]=1; F[1]=2;
- for(int i=2;i<=n+1;i++){
- for(int j=0;j<i;j++){
- if (a[j]<a[i]){
- if(F[i]<F[j]+1){
- F[i]=F[j]+1;
- vet[i]=j;
- dp[i]=dp[j];
- }
- else if (F[i]==F[j]+1){
- dp[i]=dp[i]+dp[j];
- }
- }
- }
- }
- vector < int > res;
- cout<<F[n+1]-2<<endl;
- int i= vet[n+1];
- while(i >= 0){
- if (i==0){
- res.push_back(a[i]);
- break;
- }
- else {
- res.push_back(a[i]);
- i=vet[i];
- }
- }
- for(int i=res.size()-1;i>=0;i--){
- if (res[i]!=INT_MAX && res[i]!= INT_MIN){
- cout<<res[i]<<" ";
- }
- }
- cout<<endl<<"Co tat ca "<< dp[n+1]<< " day con tang dai nhat khong lien tiep "<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment