Strongest de combat time limit: +Ms | Memory Limit:65535KB Difficulty:3
-
-
Describe
-
During the spring and Autumn period, Zhao is vast and abundant, and the people live happily. But many countries are eyeing it, ready to unite to launch a war against Zhao.
Obviously, in the face of a number of national forces to combat, Zhao's strength is clearly at a disadvantage. Combat effectiveness is a key factor in determining the success or failure of a war, in general, the combat effectiveness of a force is proportional to the troop's strength. But when a troop is divided into several combat teams, the combat effectiveness of the Force will be greatly enhanced.
The combat effectiveness of a force can be calculated by the following two rules:
1. If the strength of a combat team is n, then the combat team will have a fighting force of N;
2. If a unit is divided into several combat teams, the total combat effectiveness of the Force is the product of the combat effectiveness of these teams.
For example: The strength of a force of 5 when the effectiveness analysis is as follows:
Case |
Operational arrangements |
Total combat effectiveness. |
1 |
1,1,1,1,1 (divided into 5 combat teams) |
1*1*1*1*1=1 |
2 |
1,1,1,2 (divided into 4 combat teams) |
1*1*1*2=2 |
3 |
1,2,2 (divided into 3 combat teams) |
1*2*2=4 |
4 |
1,1,3 (divided into 3 combat teams) |
1*1*3=3 |
5 |
2,3 (divided into 2 combat teams) |
2*3=6 |
6 |
1,4 (divided into 2 combat teams) |
1*4=4 |
7 |
5 (divided into 1 combat teams) |
5=5 |
Obviously, the troops are divided into 2 combat teams (one is 2, the other is 3), the total combat effectiveness reached the maximum!
-
-
Input
-
The
-
first line: n indicates that there are n sets of test data. (2<=n<=5)
Next there are n lines, each line has an integer ti represents the strength of the Zhao Army. (1<=ti<=1000) I=1, ... N
-
-
Output
-
-
for each row of test data, the output occupies one row, and only an integer s, representing the maximum combat effectiveness of the battle arrangement.
-
-
Sample input
-
-
254
-
-
Sample output
-
-
64
-
-
Source
-
-
fifth session of Henan Province Program design Competition
-
Uploaded by
Acm_ Li Rubing
Problem Solving Ideas:
Remember this rule, when you can split the number into the same case, the product is the largest of the case is 2 and 3 of these two numbers.
#include <stdio.h> #include <cmath> #include <string.h> #include <algorithm>using namespace std ; int Len;int b[3000],c[3000];void cheng (int jin) {int a[3000];for (int j=0;j<len;j++) {a[j]=c[j];c[j]=0;} int i; int Alen=len; for (i=0; i<alen; i++) { C[i]+=a[i]*jin; if (c[i]>=10) { c[i+1]+=c[i]/10; c[i]%=10;} } if (c[len]!=0) len++;} int main () {int t;scanf ("%d", &t), while (t--) {memset (c,0,sizeof (c)); int wc;scanf ("%d", &WC); if (wc==1| | wc==2| | wc==3) {printf ("%d\n", WC); continue;} Len=1;c[0]=1;int cc=wc%3;if (cc==1) {cc=wc/3-1;while (cc--) {Cheng (3);} Cheng (4);} else if (cc==0) {cc=wc/3;while (cc--) {Cheng (3);}} else if (cc==2) {cc=wc/3;while (cc--) {Cheng (3);} Cheng (2);} int i; for (i=len-1; i>=0; i--) if (c[i]!=0) break; for (; i>=0; i--) printf ("%d", c[i]);
Nyoj 541-strongest de combat effectiveness "large number, number of split problem"