最強DE 戰鬥力
- 描述
-
春秋戰國時期,趙國地大物博,資源非常豐富,人民安居樂業。但許多國家對它虎視眈眈,準備聯合起來對趙國發起一場戰爭。
顯然,面對多個國家的部隊去作戰,趙國的兵力明顯處於劣勢。戰鬥力是決定戰爭成敗的關鍵因素,一般來說,一支部隊的戰鬥力與部隊的兵力成正比。但當把一支部隊分成若干個作戰隊伍時,這個部隊的戰鬥力就會大大的增強。
一支部隊的戰鬥力是可以通過以下兩個規則計算出來的:
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
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;
}
}