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){
- int value[l+1];
- value[0]=0;
- for(int i=1;i<=l;i++){
- int max_value=INT_MIN;
- for(int j=1;j<=i;j++){
- max_value=max(max_value,cost[j]+value[i-j]);
- }
- value[i]=max_value;
- }
- return value[l];
- }
- // 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