Cut Ribbon
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
  1. 5 5 3 2
output
  1. 2
input
  1. 7 5 5 2
output
  1. 2
Note

In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.

In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

【题意】给你一根绳子称为d,现在要将绳子分成若干段,使得每一段的长度必须是a,b,c中的一个,求分得的最多段数。

【分析】简单DP,dp[i]代表切到当前位置获得的最大段数,慢慢更新即可。

  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define mp make_pair
  4. #define vi vector<int>
  5. #define inf 0x3f3f3f3f
  6. using namespace std;
  7. typedef long long LL;
  8. const int N = 1e5+;
  9. int n;
  10. int a,b,c;
  11. int dp[N];
  12. void solve(int i,int x){
  13. if(i-x==)dp[i]=max(dp[i],);
  14. else if(i-x<)dp[i]=max(dp[i],);
  15. else dp[i]=max(dp[i],dp[i-x]==?:dp[i-x]+);
  16. }
  17. int main(){
  18. scanf("%d%d%d%d",&n,&a,&b,&c);
  19. for(int i=;i<=n;i++){
  20. solve(i,a);
  21. solve(i,b);
  22. solve(i,c);
  23. }
  24. printf("%d\n",dp[n]);
  25. return ;
  26. }

Codeforces Round #119 (Div. 2) Cut Ribbon(DP)的更多相关文章

  1. Codeforces Round #260 (Div. 2)C. Boredom(dp)

    C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  2. Codeforces Round #658 (Div. 2) D. Unmerge(dp)

    题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...

  3. Codeforces Round #471 (Div. 2) F. Heaps(dp)

    题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...

  4. 【Codeforces】Codeforces Round #374 (Div. 2) -- C. Journey (DP)

    C. Journey time limit per test3 seconds memory limit per test256 megabytes inputstandard input outpu ...

  5. Codeforces Round #652 (Div. 2) D. TediousLee(dp)

    题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...

  6. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  7. Codeforces Round #165 (Div. 1) Greenhouse Effect(DP)

    Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  9. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

随机推荐

  1. 【BZOJ4517】【SDOI2016】排列计数 [数论]

    排列计数 Time Limit: 60 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 求有多少种长度为 n 的序列 A, ...

  2. loj6102 「2017 山东二轮集训 Day1」第三题

    传送门:https://loj.ac/problem/6102 [题解] 贴一份zyz在知乎的回答吧 https://www.zhihu.com/question/61218881 其实是经典问题 # ...

  3. 基本控件文档-UILabel属性---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址   //转载请注明出处--本文永久链接:http://www.cnblogs.com/ ...

  4. springmvc4处理get和post请求中文乱码问题

    1.在springmvc4处理get和post请求的问题 参看大牛博客连接:https://blog.csdn.net/qq_41665356/article/details/80234392

  5. 关于Linux下s、t、i、a权限

    文件权限除了r.w.x外还有s.t.i.a权限: 首先我们利用umask查看系统的权限为四位,首位就是特殊权限位,SetUID为4,SetGID为2,t为1 [root@iz2ze46xi6pjjj6 ...

  6. linux下删除已经不用的配置文件

    使用命令 dpkg -l | grep -v ^ii 查看当前未安装或者不用了的配置文件 例如我的显示如下

  7. OC 07 类的扩展

    1.NSDate的使用 NSDate是Cocoa中⽤于处理⽇期和时间的基础类,封装了某⼀给定的时刻(含日期,时间,时区) 注意NSLog(@“%@”,nowDate);⽆论你是哪个时区的时间,打印时总 ...

  8. Aspxgridview 根据条件来自定义计算Totalsummery

    protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEven ...

  9. python初学-列表

    列表操作: 列表一般需要先调用方法后才能打印,不能直接打印调用的方法 因为列表可以修改 一般不会返回一个新列表 # 列表 # new_names = ['lzc','lzc2','lzc3'] # 下 ...

  10. linux 设置开机启动项两种方式

    原文链接:http://blog.csdn.net/karchar/article/details/52489572 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务. 在解问题之前 ...