zoukankan      html  css  js  c++  java
  • JZ067剪绳子

    思路

    动归 贪心

    class Solution {
    public:
        int cutRope(int number) {
            if (number < 2)
            {
                return 0;
            }
            if (number == 2)
            {
                return 1;
            }
            if(number == 3)
            {
                return 2;
            }
            int * result = new int[number+1];
            result[0] = 0;
            result[1]= 1;
            result[2] = 2;
            result[3]= 3;
            int max_val = 0;
            for (int i =4;i<=number;++i) //从4计算到number 
            {
                max_val = 0;
                for(int j = 1;j<=i/2;++j) //后面一半是重复的
                {
                    int current = result[j]*result[i-j];
                    if(max_val<current)
                        max_val = current;
                    result[i] = max_val;
                }
            }
            max_val = result[number]; //赋值之后将新申请的数组删除
            delete []result;
            return max_val;
        }
    };
    以大多数人努力程度之低,根本轮不到去拼天赋~
  • 相关阅读:
    Git push 常见用法
    Git commit 常见用法
    Git add 常见用法
    Git-仓库
    Git clone 常见用法
    Git-简介
    ZOJ Problem Set
    ZOJ Problem Set
    ZOJ Problem Set
    ZOJ Problem Set
  • 原文地址:https://www.cnblogs.com/gcter/p/15338739.html
Copyright © 2011-2022 走看看