最强DE 战斗力(nyoj541)

题意不用解释了就是求积最大,但考虑到什么时候积会是最大

a1+a2+.....an=M;

a1*a2*.....an=max;

要求当a1+...an=n 时求他们所有值得最大乘积当且仅当

a1=a2=a3=...=an

所以原式化简为

n*a=M;

max=a^n;带入解得最大的取值为3;

所以取值都是3的倍数,接下来就是个大数处理问题,最大的值会有pow(3,32)*4,所以用数组储存,开一个200的数组足够了!

代码:

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<string.h>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<vector>
 8 #include<cstring>
 9 #include<stack>
10 #include<stdlib.h>
11 #include<ctype.h>
12 using namespace std;
13 #define MAXN 1300
14 #define inf 100000
15 
16 int dp[230];
17 void acc(int x)
18 {
19     int i,t;
20     for( i=t=0;i<200;i++)
21     {
22         t=dp[i]*x+t;
23         dp[i]=t%10;
24         t=t/10;
25     }
26 }
27 int main()
28 {
29     int t,n,a;
30     cin>>t;
31     while(t--)
32     {
33         int i,j;
34         memset(dp,0,sizeof dp);
35         cin>>n;
36         a=n/3;
37         if(n%3==1)a--;//如果取余得1,那最大值就要包含一个4
38         dp[0]=1;
39         for( i=0;i<a;i++)
40             acc(3);//a个3相乘
41         if(n%3==1)acc(4);
42         else if(n%3==2)acc(2);
43         j=200;
44         while(!dp[j])
45         {
46             j--;
47         }
48         for( i=j;i>0;i--)
49             cout<<dp[i];
50         cout<<dp[0]<<endl;
51     }
52 }
View Code

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

转载于:https://www.cnblogs.com/zhaopengze/p/3738379.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值