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
  • 相关阅读:
    关于阿里云带宽监控指标记录
    mongodb备份还原
    squid3.5缓存代理实践记录
    kafka依赖zookeeper原因解析及应用场景
    Zookeeper+Kafka集群部署(转)
    dubbo框架提供Main方法运行容器的几种方式(转)
    html标签简介(常用)
    数据库中和表并列的其他对象
    外键约束
    数据库中的约束
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617218.html
Copyright © 2011-2022 走看看