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. Identity Server 4 从入门到落地(四)—— 创建Web Api

    前面的部分: Identity Server 4 从入门到落地(一)-- 从IdentityServer4.Admin开始 Identity Server 4 从入门到落地(二)-- 理解授权码模式 ...

  2. Tomcat类加载机制和JAVA类加载机制的比较

    图解Tomcat类加载机制    说到本篇的tomcat类加载机制,不得不说翻译学习tomcat的初衷.    之前实习的时候学习javaMelody的源码,但是它是一个Maven的项目,与我们自己的 ...

  3. 华为AppTouch携手全球运营商,助力开发者出海

    内容来源:华为开发者大会2021 HMS Core 6 APP services技术论坛,主题演讲<华为AppTouch携手全球运营商,助力开发者出海>. 演讲嘉宾:华为消费者云服务App ...

  4. oracle 当月日历的sql

    select max(sun) sun, max(mon) mon, max(tue) tue, max(wed) wed, max(thu) thu, max(fri) fri, max(sat) ...

  5. OSGI 理论知识

    下面列出了主要的控制台命令: 表 1. Equinox OSGi 主要的控制台命令表 类别 命令 含义 控制框架 launch 启动框架 shutdown 停止框架 close 关闭.退出框架 exi ...

  6. 【编程思想】【设计模式】【行为模式Behavioral】Publish_Subscribe

    Python版 https://github.com/faif/python-patterns/blob/master/behavioral/publish_subscribe.py #!/usr/b ...

  7. liunx 安装ActiveMQ 及 spring boot 初步整合 activemq

    源码地址:  https://gitee.com/kevin9401/microservice.git 一.安装 ActiveMQ: 1. 下载 ActiveMQ wget  https://arch ...

  8. jQuery遍历的几种方式

    一.jQuery对象遍历 1 <script type="text/javascript" src="js/jquery-3.4.1.js">< ...

  9. 【C/C++】BanGDream活动点数计算器

    作为一个白嫖咸鱼,我每个活动都只打出三星卡就不玩了,于是写了一个模拟器,算算还要打几把hhh #include <iostream> #include <algorithm> ...

  10. 【C/C++】习题3-7 DNA/算法竞赛入门经典/数组与字符串

    [题目] 输入m组n长的DNA序列,要求找出和其他Hamming距离最小的那个序列,求其与其他的Hamming距离总和. 如果有多个序列,求字典序最小的. [注]这道题是我理解错误,不是找出输入的序列 ...