Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N=2001;
- int len;
- int n,temp;
- int cost[N];
- void price(){
- for(int i=1;i<=n;i++){
- cin>>cost[i];
- }
- }
- int cutRod(int l){
- bool done[n];
- int value[n];
- memset(value,0,n);
- memset(done,0,n);
- int max_Value=INT_MIN;
- if(l<=0) return 0;
- for(int i=1;i<=l;i++){
- if(done[l-i]) {
- temp=value[l-i];
- }
- else {
- temp=cutRod(l-i);
- done[l-i]=true;
- value[l-i]=temp;
- }
- max_Value=max (max_Value,cost[i]+temp);
- }
- return max_Value;
- }
- // len<=n : YES
- int main() {
- cin>>len;
- cin>>n;
- price();
- cout<<cutRod(len);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement