码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 189A Cut Ribbon

时间:2015-07-02 22:22:36      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

Cut Ribbon

Time Limit: 2000ms
Memory Limit: 262144KB
This problem will be judged on CodeForces. Original ID: 189A
64-bit integer IO format: %I64d      Java class name: (Any)

Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:

  • After the cutting each ribbon piece should have length ab or c.
  • After the cutting the number of ribbon pieces should be maximum.

 

Help Polycarpus and find the number of ribbon pieces after the required cutting.

 

Input

The first line contains four space-separated integers nab 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 ab and c can coincide.

 

Output

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

 

Sample Input

Input
5 5 3 2
Output
2
Input
7 5 5 2
Output
2

Source

 
解题:随便dp下
 
技术分享
 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 }
View Code

 

CodeForces 189A Cut Ribbon

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4617218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!