| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 890 人关注过本帖
标题: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
帖 子:570
专家分:3727
注 册:2019-7-29
收藏
得分:20 
#include<iostream>

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

要在一行,不要换行

一沙一世界,一花一天堂。无限掌中置,刹那成永恒。
2020-10-08 14:05
快速回复:C++实现求一个整数的K拆分乘积最大值
数据加载中...
 
   



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

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