最强DE 战斗力
时间限制:
1000 ms | 内存限制:
65535 KB
难度:3
-
描述
-
春秋战国时期,赵国地大物博,资源非常丰富,人民安居乐业。但许多国家对它虎视眈眈,准备联合起来对赵国发起一场战争。
显然,面对多个国家的部队去作战,赵国的兵力明显处于劣势。战斗力是决定战争成败的关键因素,一般来说,一支部队的战斗力与部队的兵力成正比。但当把一支部队分成若干个作战队伍时,这个部队的战斗力就会大大的增强。
一支部队的战斗力是可以通过以下两个规则计算出来的:
1.若一支作战队伍的兵力为N,则这支作战队伍的战斗力为N;
2.若将一支部队分为若干个作战队伍,则这支部队的总战斗力为这些作战队伍战斗力的乘积。
比如:一支部队的兵力为5时的战斗力分析如下:
显然,将部队分为2个作战队伍(一个为2,另一个为3),总的战斗力达到最大!情况
作战安排
总的战斗力
1
1,1,1,1,1(共分为5个作战队伍)
1*1*1*1*1=1
2
1,1,1,2 (共分为4个作战队伍)
1*1*1*2=2
3
1,2,2 (共分为3个作战队伍)
1*2*2=4
4
1,1,3 (共分为3个作战队伍)
1*1*3=3
5
2,3 (共分为2个作战队伍)
2*3=6
6
1,4 (共分为2个作战队伍)
1*4=4
7
5 (共分为1个作战队伍)
5=5
-
输入
-
第一行: N表示有N组测试数据. (2<=N<=5)
接下来有N行,每行有一个整数Ti 代表赵国部队的兵力. (1<=Ti<=1000) i=1,…N
输出
- 对于每一行测试数据,输出占一行,仅一个整数S,表示作战安排的最大战斗力. 样例输入
-
2
-
5
-
4
样例输出
-
6
-
4
-
第一行: N表示有N组测试数据. (2<=N<=5)
package acm.ny;
import java.math.BigInteger;
import java.util.Scanner;
public class Ny0541_10130420_1536 {
private static BigInteger [] result = new BigInteger[1001];
static{
int temp ;
result[0] = BigInteger.ZERO;
result[1] = BigInteger.ONE;
result[2] = BigInteger.valueOf(2);
result[3] = BigInteger.valueOf(3);
for(int i = 4; i < result.length; ++i){
result[i] = BigInteger.ZERO;
temp = i>>1;
for(int j = 1; j <= temp; ++j){
if(result[i].compareTo(result[j].multiply(result[i-j])) < 0){
result[i] = result[j].multiply(result[i-j]);
}
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int cases,t;
cases = in.nextInt();
while(cases-->0){
t = in.nextInt();
System.out.println(result[t]);
}
}
private static BigInteger solve(int num){
if(num <= 4){
return BigInteger.valueOf(num);
}
int count = num/3;
int mod = num%3;
BigInteger three = BigInteger.valueOf(3);
switch(mod){
case 0:
return three.pow(count);
case 1:
return three.pow(count-1).multiply(BigInteger.valueOf(4));
case 2:
return three.pow(count).multiply(BigInteger.valueOf(2));
}
return three;
}
}