Codeforces Round #119 (Div. 2)A. Cut Ribbon
1 second
256 megabytes
standard input
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 a, b 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.
The first line contains four space-separated integers n, a, b 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 a, b and c can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
5 5 3 2
2
7 5 5 2
2
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.
这题n^2枚举可以解决,但是也可以用dp O(n)啊
dp得到的数。
dp[i]代表 组成i 需要的最多ribbon块数。
/* ***********************************************
Author :guanjun
Created Time :2016/10/7 18:22:02
File Name :cf119a.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int dp[];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,a,b,c;
while(cin>>n>>a>>b>>c){
cle(dp);
dp[a]=dp[b]=dp[c]=;
for(int i=;i<=n;i++){
if(i>a&&dp[i-a])dp[i]=max(dp[i],dp[i-a]+);
if(i>b&&dp[i-b])dp[i]=max(dp[i],dp[i-b]+);
if(i>c&&dp[i-c])dp[i]=max(dp[i],dp[i-c]+);
}
cout<<dp[n]<<endl;
}
return ;
}
Codeforces Round #119 (Div. 2)A. Cut Ribbon的更多相关文章
- 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 ...
- Codeforces Round #119 (Div. 2)
A. Cut Ribbon \(f(i)\)表示长为\(i\)的布条最多可以剪几段. B. Counting Rhombi \(O(wh)\)枚举中心计算 C. Permutations 将序列一映射 ...
- 【推导】Codeforces Round #484 (Div. 2) C. Cut 'em all!
题意:给你一棵树,让你切掉尽可能多的边,使得产生的所有连通块都有偶数个结点. 对于一棵子树,如果它有奇数个结点,你再从里面怎么抠掉偶数结点的连通块,它都不会变得合法.如果它本来就有偶数个结点,那么你怎 ...
- Educational Codeforces Round 119 (Div. 2), (C) BA-String硬着头皮做, 能做出来的
题目链接 Problem - C - Codeforces 题目 Example input 3 2 4 3 a* 4 1 3 a**a 6 3 20 **a*** output abb abba b ...
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #456 (Div. 2)
Codeforces Round #456 (Div. 2) A. Tricky Alchemy 题目描述:要制作三种球:黄.绿.蓝,一个黄球需要两个黄色水晶,一个绿球需要一个黄色水晶和一个蓝色水晶, ...
- 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- gitlab恢复、迁移
文件说明 安装包:gitlab-ce_8.11.5-ce.0_amd64.deb 备份的数据:533751277_gitlab_backup.tar 系统:Ubuntu 16.04.4 LTS \n ...
- spring boot MongoDb配置和多数据源
配置文件: # MongoDB配置项 mongodb.base.host: 192.168.1.204 mongodb. mongodb.base.database: xxx mongodb.base ...
- jenkins部署遇到离线问题如何解决
部署jenkins页面时遇到离线问题如何解决 部署jenkins遇到一个问题,然后告诉我你的jenkins已经离线,什么鬼,后来找了很多博客 后来自己终于验证成功了,也分享给大家,只需把https改为 ...
- python的webservice请求
1.pip install client 2.pip install suds-jurko #coding=utf-8from suds.client import Clientimport time ...
- HDU - 2041 - 超级楼梯(dp)
题意: 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? 思路: 如何到第n阶台阶,只能从n-1和n-2台阶上去,那么只需要计算到n-1阶台阶和到n-2阶台 ...
- C++关键字:explicit
#include "pch.h" #include <iostream> using namespace std; class BaseClass { public: ...
- Oracle 回滚(ROLLBACK)和撤销(UNDO)
一.回滚(ROLLBACK)和撤销(UNDO) 回滚和前滚是保证Oracle数据库中的数据处于一致性状态的重要手段. 在9i版本以前 Oracle使用数据库中的回滚段来实现未提交数据或因系统故障导致实 ...
- CCF201609-2 火车购票 java(100分)
试题编号: 201609-2 试题名称: 火车购票 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一 ...
- window7 上创建定时任务来运行自动化脚本
跌跌撞撞,坑坑洼洼,终于把公司一个小模块的接口测试脚本写完了,一共有20多个吧!后来发现每天自己去运行一键执行的脚本太麻烦,所以想用windows的定时任务来解决这个问题!今天看了篇文章,所以决定实践 ...
- 2.Linux文件IO编程
2.1Linux文件IO概述 2.1.0POSIX规范 POSIX:(Portable Operating System Interface)可移植操作系统接口规范. 由IEEE制定,是为了提高UNI ...