Friday, 19 December 2014

cut ribbon (imp dp question)

cut ribbon


#include<iostream>
using namespace std;
int n,dp[4005],i,j,a;
int main(){
 fill(dp+1,dp+4005,-1e9);cin >> n;
 for(j=1;j<=3;j++){ cin >> a; for(i=a;i<=n;i++) dp[i]=max(dp[i-a]+1,dp[i]); }
 cout<<dp[n];return 0;
}


similar questions to practice  on spoj
piggy bank , buying apples