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
  • 相关阅读:
    Domain Logic approaches
    Comparing Spring AOP and AspectJ
    CDI Features
    Java Design Patterns
    第二阶段:代码片段
    第一阶段:学生在线系统需求分析报告
    load data语句实验报告
    Sping AOP Capabilities and Goals
    Java Design Patterns
    CDI Features
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617218.html
Copyright © 2011-2022 走看看