标题:C++实现求一个整数的K拆分乘积最大值
只看楼主
我莹莹
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2020-2-26
结帖率:50%
已结贴  问题点数:20 回复次数:1 
C++实现求一个整数的K拆分乘积最大值
在网上找的,怎么用不起来。大咖们帮忙看看,谢谢。

#include<iostream>                                                                                                                                                                        
using namespace std;                                                                                    
int main()
{                                                                                                   
   int num,result;                                                                                 
   cin>>num;                                                                                       
   if(num<2)                                                                                       
       result=0;                                                                                   
   if(num==2)                                                                                      
       result=1;                                                                                   
   if(num==3)                                                                                      
       result=2;                                                                                   
   if(num>3)                                                                                       
     {                                                                                               
     int* dp=new int[num+1];                                                                                                                                                               
     dp[1]=1;                                                                                       
     dp[2]=2;                                                                                       
     dp[3]=3;                                                                                       
     for(int i=4;i<=num;i++)                                                                        
     {                                                                                               
         int current_max=-1;                                                                        
         for(int j=1;j<=i/2;j++)                                                                     
         {                                                                                          
             if(dp[j]*dp[i-j]>current_max)                                                           
                 current_max=dp[j]*dp[i-j];                                                         
         }                                                                                          
         dp[i]=current_max;                                                                          
     }                                                                                               
         result=dp[num];                                                                             
                                                                                                     
     }                                                                                               
     cout<<result<<endl;                                                                             
     return 0;                                                                                       

}         

  提示这样的
1:188: fatal error: iostream: No such file or directory
 #include
                                                                                                                                                                                            ^
compilation terminated.
搜索更多相关主题的帖子: 整数 C++ num result int 
2020-10-07 20:13
纯蓝之刃
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:76
帖 子:554
专家分:3690
注 册:2019-7-29
得分:20 
#include<iostream>

int* dp=new int[num+1];

要在一行,不要换行

一沙一世界,一花一天堂。无限掌中置,刹那成永恒。
2020-10-08 14:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-503377-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.238367 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved