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 nnn. He wants to cut the ribbon in a way that fulfils the following two conditions:

  • After the cutting each ribbon piece should have length aaa, bbb or ccc.
  • 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 nnn, aaa, bbb and ccc (1 ≤ n, a,b, c≤ 4000)(1 ≤ n, a,b, c≤ 4000)(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 aaa, bbb and ccc 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

5 5 3 2

output

2

input

7 5 5 2

output

2

Note

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

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

Solve

完全背包,看成给出三种商品,恰好能够装满背包的情况

注意初始化的问题,如果把dpdpdp数组全部初始化为−1-1−1的话,需要注意dp[j]=−1&&dp[j−a[i]]=−1dp[j]=-1\&\&dp[j-a[i]]=-1dp[j]=−1&&dp[j−a[i]]=−1的情况。或者就全部初始值给成小于−1-1−1的数

Code

/*************************************************************************

	 > Author: WZY
> School: HPU
> Created Time: 2019-04-01 18:30:38 ************************************************************************/
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstring>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <random>
#define ll long long
#define ull unsigned long long
#define lson o<<1
#define rson o<<1|1
#define ms(a,b) memset(a,b,sizeof(a))
#define SE(N) setprecision(N)
#define PSE(N) fixed<<setprecision(N)
#define bug cerr<<"-------------"<<endl
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
#define LEN(A) strlen(A)
const double E=exp(1);
const double eps=1e-9;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int maxn=1e6+10;
const int maxm=1e3+10;
const int moha=19260817;
const int inf=1<<30;
const ll INF=1LL<<60;
using namespace std;
inline void Debug(){cerr<<'\n';}
inline void MIN(int &x,int y) {if(y<x) x=y;}
inline void MAX(int &x,int y) {if(y>x) x=y;}
inline void MIN(ll &x,ll y) {if(y<x) x=y;}
inline void MAX(ll &x,ll y) {if(y>x) x=y;}
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
cerr<<arg<<"";Debug(rest...);}
int dp[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);cin.tie(0);
cout.precision(20);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
srand((unsigned int)time(NULL));
#endif
int n;
int a[4];
cin>>n>>a[0]>>a[1]>>a[2];
ms(dp,-1);
dp[0]=0;
for(int i=0;i<3;i++)
for(int j=a[i];j<=n;j++)
if(dp[j-a[i]]!=-1)
MAX(dp[j],dp[j-a[i]]+1);
cout<<dp[n]<<endl;
#ifndef ONLINE_JUDGE
cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s.\n";
#endif
return 0;
}

Codeforces 189A:Cut Ribbon(完全背包,DP)的更多相关文章

  1. Codeforces 189A. Cut Ribbon

    题目链接:http://codeforces.com/problemset/problem/189/A 题意: 给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条 ...

  2. Codeforces 730J:Bottles(背包dp)

    http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...

  3. Codeforces 922 E Birds (背包dp)被define坑了的一题

    网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...

  4. 【CF 189A Cut Ribbon】dp

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...

  5. codeforces 148E Aragorn's Story 背包DP

    Aragorn's Story Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/probl ...

  6. CF 189A Cut Ribbon

    #include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int ...

  7. Codeforces 922 思维贪心 变种背包DP 质因数质数结论

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  8. Codeforces Round #119 (Div. 2) Cut Ribbon(DP)

    Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  10. Codeforces Round #119 (Div. 2)A. Cut Ribbon

    A. Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. Struts 2 基础篇【转】

    转载至 : http://www.blogjava.net/huamengxing/archive/2009/10/21/299153.html Struts2架构图 有视频讲解百度一下就可以找到了 ...

  2. 【leetcode】633. Sum of Square Numbers(two-sum 变形)

    Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c. ...

  3. ubantu打开摄像头失败

    摘要-针对ubantu20 sudo apt install v4l-utils v4l2-ctl --list-devices - cv2 install on ubantu20```针对ubant ...

  4. Linux学习 - 文件包处理命令

    一.搜索文件find find  [搜索范围]  [匹配条件] (1) -name(名字查找) <1>  find  /etc  -name  init 查找/etc下以 "in ...

  5. Shell脚本实现乱序排列文件内容的多种方法(洗牌问题)

    洗牌问题:洗一副扑克,有什么好办法?既能洗得均匀,又能洗得快?即相对于一个文件来说怎样高效率的实现乱序排列? ChinaUnix 确实是 Shell 高手云集的地方,只要你想得到的问题,到那里基本上都 ...

  6. 聊聊 SpringBoot 中的两种占位符:@*@ 和 ${*}

    前言 在 SpringBoot 项目中,我们经常会使用两种占位符(有时候还会混用),它们分别是: @*@ ${*} 如果我们上网搜索「SpringBoot 的占位符 @」,大部分答案会告诉你,Spri ...

  7. Flink Exactly-once 实现原理解析

    关注公众号:大数据技术派,回复"资料",领取1024G资料. 这一课时我们将讲解 Flink "精确一次"的语义实现原理,同时这也是面试的必考点. Flink ...

  8. 转:Android preference首选项框架

    详解Android首选项框架ListPreference 探索首选项框架 在 深入探讨Android的首选项框架之前,首先构想一个需要使用首选项的场景,然后分析如何实现这一场景.假设你正在编写一个应用 ...

  9. Python pyecharts绘制饼图

    一.pyecharts绘制饼图语法简介 饼图主要用于表现不同类目的数据在总和中的占比.每个的弧度不是数据量的占比pie.add()方法的用法add(name, attr, value, radius= ...

  10. 【web】docker复现环境踩坑

    在先知看到有师傅发了个学习 P 牛的代码审计的文章,在 github 上下下来复现环境,结果 docker 各种问题,气死 安装 docker-compose:pip install -i https ...