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. 巩固java第四天

    巩固内容: HTML 元素 HTML 文档由 HTML 元素定义. HTML 元素 开始标签 * 元素内容 结束标签 * <p> 这是一个段落 </p> <a href= ...

  2. 【swift】Xcode未响应(卡死、卡住、CPU满载、忙碌、转圈圈)

    在尝试了网上的方法,依然没能解决问题,尝试如下: 1.去自己项目的路径,找到<你的项目名.xcodeproj>,点击[显示包内容],删除xcuserdata文件夹 2.去Library,把 ...

  3. Oracle中创建DB LINK

    当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据库一样访问远程数据库表中的数据.下面讲介绍如何在本地数 ...

  4. mysql报错max_connections错误

    SELECT @@MAX_CONNECTIONS AS 'Max Connections';set GLOBAL max_connections=10000; show status like '%t ...

  5. fastjson过滤多余字段

    /**     * Description:过滤实体中的字段     * @param src 需要过滤的对象,如 list,entity     * @param clazz 实体的class    ...

  6. App内容分享

    1.发送文本内容 发送简单的数据到其他应用,比如社交分分享的内容,意图允许用户快速而方便的共享信息. //分享简单的文本内容 public void btnShareText(View view) { ...

  7. MySQL(4):卸载MySQL

    MySQL的安装是比较复杂的,一旦安装出现错误或者出现其他问题,我们想要完全卸载MySQL也是非常麻烦的,下面简单说下怎样可以完全干净的卸载MySQL 卸载步骤 第一步:用管理员的身份打开命令窗口,关 ...

  8. java通过反射获取Java对象属性值

    说明: 作为反射工具类,通过对象和属性的名字获取对象属性的值,如果在当前对象属性没有找到,依次向上收集所有父类的属 性,直到找到属性值,没有找到返回null: 代码: 1.classUtil pack ...

  9. java客户端的elasticSearch索引库的相关操作

    package com.hope.es;import org.elasticsearch.client.transport.TransportClient;import org.elasticsear ...

  10. 使用AOP思想实现日志的添加

    //1.创建日志表syslog------->创建日志的实体类--------->在web.xml中配置监听 <listener>     <listener-class ...