标签:
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:
Help Polycarpus and find the number of ribbon pieces after the required cutting.
The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
5 5 3 2
2
7 5 5 2
2
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 8010; 4 int dp[maxn],n,piece[3]; 5 int main() { 6 scanf("%d %d %d %d",&n,piece,piece+1,piece+2); 7 memset(dp,0,sizeof dp); 8 for(int i = 0; i <= n; ++i) { 9 for(int j = 0; j < 3; ++j) 10 dp[i+piece[j]] = max(dp[i+piece[j]],(dp[i]||i == 0)?dp[i] + 1:0); 11 } 12 printf("%d\n",dp[n]); 13 return 0; 14 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4617218.html