codeforces——189A——Cut Ribbon
来源:互联网 发布:网络平台合作协议 编辑:程序博客网 时间:2024/06/05 01:53
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 andc (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 numbersa, b andc 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.
输入缎带长度和三种要求尺寸,问最多能把缎带分成几份(必须只有所给三种尺寸)
背包
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<map>#define MAX 9223372036854775807using namespace std;int main(){ int n,a[4]; while(~scanf("%d%d%d%d",&n,&a[0],&a[1],&a[2])) { int dp[5005]; memset(dp,-1,sizeof(dp)); dp[0]=0; for(int i=0; i<3; i++) for(int j=a[i]; j<=n; j++) if(dp[j-a[i]]!=-1) dp[j]=max(dp[j],dp[j-a[i]]+1); cout<<dp[n]<<endl; } return 0;}
- codeforces——189A——Cut Ribbon
- codeforces 189A Cut Ribbon
- CodeForces 189A Cut Ribbon
- CodeForces 189A-Cut Ribbon
- codeforces 189A. Cut Ribbon
- CodeForces 189A Cut Ribbon
- Codeforces-189A-Cut Ribbon
- codeforces 189a Cut Ribbon 水dp
- CF - 189A - Cut Ribbon
- CF 189A Cut Ribbon
- CF 189 A Cut Ribbon
- CF 189A Cut Ribbon
- A. Cut Ribbon
- codefroces A. Cut Ribbon
- Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)
- Codeforces 189A. Cut Ribbon 完全背包装满最多装下物品的个数
- Codeforces Round #119 (Div. 2) A. Cut Ribbon
- Codeforces189 A. Cut Ribbon(DP)
- javascript中数据类型值的存储方式和位置
- PCA(主成分)分析及MATLAB实现
- jQuery选择器2
- 由阮一峰的博客想到的
- Spring AOP——面向切面编程(上)
- codeforces——189A——Cut Ribbon
- css基础(未完待续)
- phpstorm技巧随笔
- Ubuntu16.04 + cuda8.0 + GTX1080 + matlab14.04a + Opencv3.0 + caffe 安装教程
- 欢迎使用CSDN-markdown编辑器
- 省队集训DAY4
- CAS单点登录报错 org.jasig.cas.client.util.XmlUtils 必须由匹配的结束标记
- 好看的人太多,有趣的人太少
- windows中使用make