Codeforces 189A. Cut Ribbon
题目链接:http://codeforces.com/problemset/problem/189/A
题意:
给你一个长度为 N 的布条, 再给你三个长度 a, b , c.你可以用剪刀去剪这些布条, 但是每次剪完后, 布条的长度必须是 a 或者 b 或者 c, 问按照这个规则, 最多可以把这个布条剪成几段.
思路:
上述问题可以换一种说法, 这里有无线个长度为 a, b, c的布条, 让你选择最多的个数, 使得其连接起来长度恰好为 N.这很显然是根基础的完全背包的拓展问题.所以只解套用模板就好.
dp[i] = max( dp[i], dp[ i - v[j] ] + w[j] ).
代码:
#include <iostream>
#include <algorithm> using namespace std;
typedef long long LL;
const int MAXN = ;
int dp[MAXN + ] = {}; int main() {
ios_base::sync_with_stdio(); cin.tie();
int n, abc[]; cin >> n >> abc[] >> abc[] >> abc[];
for(int i = ; i <= n; i++) dp[i] = -; //dp[0] 初始化为 0, 其他初始化为负无穷
for(int i = ; i < ; i++) for(int j = abc[i]; j <= n; j++) dp[j] = max(dp[j], dp[j - abc[i]] + );
cout << dp[n] << endl;
return ;
}
Codeforces 189A. Cut Ribbon的更多相关文章
- 【CF 189A Cut Ribbon】dp
题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...
- CF 189A Cut Ribbon
#include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int ...
- 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
A. Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 189A:Cut Ribbon(完全背包,DP)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- CodeForces 189A 166E 【DP ·水】
非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存 ...
- Cut Ribbon
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the follo ...
- [CF189A]Cut Ribbon(完全背包,DP)
题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...
- Codeforces --- 982C Cut 'em all! DFS加贪心
题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1input ...
随机推荐
- 纯css实现 switch开关
<!-- 直接看代码,利用了css3兄弟选择器 --><!-- html --> <button class="switch"> <inp ...
- POJ1087:A Plug for UNIX(最大流)
A Plug for UNIX 题目链接:https://vjudge.net/problem/POJ-1087 Description: You are in charge of setting u ...
- 两个神奇的函数~~~sscanf、atoi
sscanf 对你没有看错 多了一个s 这个函数有什么作用呢 功能:读取字符串中的int.double.long.long long .float and so on 类型的数据 譬如说 我现在读入了 ...
- AWS文档与用户指南
AWS Command Line Interface http://docs.amazonaws.cn/cli/latest/userguide/cli-chap-welcome.html VM Im ...
- Sed basic and practice
定义:Sed 是针对数据流的非交谈式编辑器,它在命令行下输入编辑命令并指定文件,然后可以在屏幕上看到编辑命令的输出结果. 好处:Sed 在缓冲区内默认逐行处理数据,所以源文件不会被更改和破坏. 格式: ...
- eclipse调试java技巧
详细内容请看: http://www.oschina.net/question/82993_69439
- Java Web转发和重定向问题
0x01:转发情况.转发过程中,只请求一次,request对象设置了之后会一直存在,直到下一次请求. 0x02:重定向情况.会发生两次请求,如果设置了request对象,那么重定向之后,request ...
- Django项目知识点汇总
目录 一.wsgi接口 二.中间件 三.URL路由系统 四.Template模板 五.Views视图 六.Model&ORM 七.Admin相关 八.Http协议 九.COOKIE 与 SES ...
- linux基础(2)
Linux基础题 作业一:1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”useradd natashagroupmod -g 555 natashauser ...
- request.getParameterValues与request.getParameter的区别
一. 简单的对比 request.getParameter用的比较多,相对熟悉 request.getParameterValues(String name)是获得如checkbox类(名字相同, ...