题目链接: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的更多相关文章

  1. 【CF 189A Cut Ribbon】dp

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:一个长度为n的纸带,允许切割若干次,每次切下的长度只能是{a, b, c}之一.问最多能切 ...

  2. CF 189A Cut Ribbon

    #include<bits/stdc++.h> using namespace std; const int maxn = 4000 + 131; int n, a, b, c; int ...

  3. 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 ...

  4. 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 ...

  5. Codeforces 189A:Cut Ribbon(完全背包,DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  6. CodeForces 189A 166E 【DP ·水】

    非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存 ...

  7. Cut Ribbon

    Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the follo ...

  8. [CF189A]Cut Ribbon(完全背包,DP)

    题目链接:http://codeforces.com/problemset/problem/189/A 题意:给你长为n的绳子,每次只允许切a,b,c三种长度的段,问最多能切多少段.注意每一段都得是a ...

  9. Codeforces --- 982C Cut 'em all! DFS加贪心

    题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1input ...

随机推荐

  1. 【题解】HNOI2016树

    大概最近写的这些题目都是仿生的代码……在这里先说明一下.可能比起做题记录来说更加像是学习笔记吧.之所以这样做主要还是因为感受到最近做的很多题目自己会做的都比较简单,不会做的又不敢触及,虽然也有所进步. ...

  2. [Leetcode] Anagrams 颠倒字母构成词

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  3. HDOJ.2064 汉诺塔III

    汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  4. GDB使用小记

    By francis_hao Nov 7,2016   记录GDB常用功能.   GDB可以让你查看一个程序在运行时其内部发生了什么,或者当一个程序崩溃时发生了什么(通过使用GDB查看core dum ...

  5. Robot POJ - 1376

    The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...

  6. 注意@Bean中的initMethod和destroyMethod

    @Configuration public class AppConfig { @Bean(initMethod = "init") public Foo foo() { retu ...

  7. 有关spring的各种下载资料的网站

    spring的文件和jar包下载的网站: https://repo.spring.io/release/org/springframework/spring/ spring 各个版本源码下载的资料: ...

  8. 接口认证方式:Bearer Token

    因为HTTP协议是开放的,可以任人调用.所以,如果接口不希望被随意调用,就需要做访问权限的控制,认证是好的用户,才允许调用API. 目前主流的访问权限控制/认证模式有以下几种: 1),Bearer T ...

  9. 【uva11468-Substring】AC自动机+dp

    http://acm.hust.edu.cn/vjudge/problem/31655 题意:给定k个模板串,n个字符以及选择它的概率pro[i],要构造一个长度问L的字符串s,问s不包含任意一个模板 ...

  10. bzoj 2749 杂题

    我们可以发现,phi(x)与x相比,相当于x的每个质因子-1后再分解质因数,添加到现有的质因子中,比如质因子13相当于将13变成12,然后分解成2*2*3,再将2的质数+2,3的指数+1,除了质因子2 ...