zoukankan      html  css  js  c++  java
  • CodeForces 189A Cut Ribbon

    Cut Ribbon

    Time Limit: 2000ms
    Memory Limit: 262144KB
    This problem will be judged on CodeForces. Original ID: 189A
    64-bit integer IO format: %I64d      Java class name: (Any)

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

     

    Input

    The first line contains four space-separated integers nab 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 ab and c 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.

     

    Sample Input

    Input
    5 5 3 2
    Output
    2
    Input
    7 5 5 2
    Output
    2

    Source

     
    解题:随便dp下
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 8010;
     4 int dp[maxn],n,piece[3];
     5 int main() {
     6     scanf("%d %d %d %d",&n,piece,piece+1,piece+2);
     7     memset(dp,0,sizeof dp);
     8     for(int i = 0; i <= n; ++i) {
     9         for(int j = 0; j < 3; ++j)
    10             dp[i+piece[j]] = max(dp[i+piece[j]],(dp[i]||i == 0)?dp[i] + 1:0);
    11     }
    12     printf("%d
    ",dp[n]);
    13     return 0;
    14 }
    View Code
  • 相关阅读:
    所谓经济现象
    高旻寺德林老和尚开示
    3Delight NSI: A Streamable Render API
    Play vue.js with constant value in SailsJS
    天魔心法之——识人篇
    对国内IoT的展望
    对国内AR产业的预言
    简评某中国工程师嫌疑窃取苹果自动驾驶技术
    评估人类的金三角模型
    Odoo 进销存报表现已开源
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617218.html
Copyright © 2011-2022 走看看