Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] Tower of hanoi [C++] #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Dynamic Programming/towerofhanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>
using namespace std;
long long int max(long long int a,long long int b){
if(a>=b){return a; }
else{return b;}
}

int main(){
int t;
cin>>t;
while(t--){
int m;
cin>>m;
vector<long long int>a(m);vector<long long int>b(m);
for(int i=0;i<m;i++){
cin>>a[i]>>b[i];

}
vector< pair<long long int,long long int> >v;
for(int i=0;i<m;i++){v.push_back(make_pair(a[i],b[i]));}
sort(v.begin(),v.end());
vector<long long int>ans(m);
ans[0]=v[0].second;long long int n=ans[0];
for(int i=1;i<m;i++){ans[i]=v[i].second;
for(int j=0;j<i;j++){
if(v[i].second>v[j].second && v[i].first>v[j].first){
ans[i]=max(ans[i],v[i].second+ans[j]);

}
}

if(n<=ans[i]){n=ans[i];}
}

cout<<n<<endl;






}




}
Binary file added towerofhanoi.obj
Binary file not shown.
Binary file added vc140.pdb
Binary file not shown.