Tag: Style IO color sp for strong on data problem
T7 the strongest de combat effectiveness
Time limit: Ms | Memory Limit: 65535KB
"Problem description"
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"
2
5
4
"Sample Output"
6
4
Code:
#include <stdio.h>
#define N 180
int dp[1001][n+1];
void Fun ()
{
dp[0][n]=0;
Dp[1][n]=1;
dp[2][n]=2;
dp[3][n]=3;
dp[4][n]=4;
int i,j;
for (i=5;i<=1000;i++)
{
for (j=n;j>=0;j--)
{
DP[I][J]=DP[3][N]*DP[I-3][J];
}
for (j=n;j>=0;j--)
{
while (DP[I][J]>9)
{
DP[I][J-1]+=DP[I][J]/10;
dp[i][j]=dp[i][j]%10;
j--;
}
}
}
}
int main ()
{
int t,n,i,j;
scanf ("%d", &t);
Fun ();
while (t--)
{
scanf ("%d", &n);
i=0;
while (dp[n][i]==0)
i++;
for (j=i;j<=n;j++)
printf ("%d", dp[n][j]);
printf ("\ n");
}
return 0;
}
The strongest de combat effectiveness