Describe
Tintin recently indulged in a number game. The game seems simple, but after many days of research, Tintin found that it was not easy to win the game under simple rules. The game is like this, in front of you there is a circle of integers (total n), you have to divide it into m parts in order, the number of parts within the sum of the sum of the m results of 10 modulo and then multiply, and finally get a number k. The requirement of the game is to make your K max or Min.
Format input Format
The first line of the input file has two integers, n (1≤n≤50) and M (1≤m≤9). The following n rows have an integer in each row, with an absolute value not greater than 104, given in order of the number in the circle, and end to end.
Output format
The output file has two lines, each containing a non-negative integer. The first line is the minimum value your program gets, and the second row is the maximum value.
Example 1 sample input 1[copy]
4 243-12
Sample output 1[Copy]
781
Limit
Each test point 1S,128MB
Analysis:
F_MAX[I][J] represents the number of first I, the maximum value of J
F_MIN[I][J] represents the number of first I, the smallest value of j
Here are two kinds of transfer order, the first is wrong, the second is right, the two are in order ...
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cmath>5#include <cstring>6#include <algorithm>7 using namespacestd;8typedefLong LongLL;9 ConstLL mod=Ten;Ten ConstLL max_n= +; One ConstLL max_m= -; A LL n,m; - LL A[max_n]; - LL Sum[max_n]; the LL B[max_n]; -LL F_max[max_n][max_m];//F[i][j] Number of previous I, divided into the maximum value of J part -LL F_min[max_n][max_m];//F[i][j] The number of previous I, divided into the minimum value of J part - voidCalc (); + voidmove_a (LL); - LL MAX; +LL min=0x3f3f3f3f; A intMain () { at -scanf"%lld%lld",&n,&M); - for(LL i=1; i<=n;i++){ -scanf"%lld",&a[i]); -b[i]=A[i]; -sum[i]=sum[i-1]+B[i]; in } - to Calc (); + for(LL i=1; i<=m+1; i++) {//Sequence Backward I units - move_a (i); the Calc (); * } $ Panax Notoginsengcout<<min<<endl<<max<<Endl; - the return 0; + } A voidCalc () { thememset (F_min,0,sizeof(F_min)); +memset (F_max,0,sizeof(F_max)); -memset (F_min,0x3f3f3f3f,sizeof(F_min)); $f_max[0][0]=1; $f_min[0][0]=1; - for(LL i=1; i<=n;i++){ -f_max[i][1]= (sum[i]%mod+mod)%MOD; thef_min[i][1]= (sum[i]%mod+mod)%MOD; - }Wuyi /*this is wrong. the For (LL i=2;i<=n;i++) {//Front I number - For (LL j=2;j<=m&&j<=i;j++) {//Split into J section Wu For (LL k=j-1;k<i;k++) {//truncated once from K - F_max[i][j]=max (F_max[i][j], (f_max[k][j-1]* (((sum[i]-sum[k)) %mod+mod))); About f_min[i][j]=min (F_min[i][j], (f_min[k][j-1]* (((sum[i]-sum[k)) %mod+mod))); $ } - } - } - */ A //The next one is right. + for(LL j=2; j<=m;j++) {//into the J section the for(LL i=j;i<=n;i++) {//number of previous I - for(LL k=j-1; k<i;k++) {//truncate once from K $F_max[i][j]=max (F_max[i][j], (f_max[k][j-1]* (((sum[i]-sum[k))%mod+mod)%MOD )); theF_min[i][j]=min (F_min[i][j], (f_min[k][j-1]* (((sum[i]-sum[k))%mod+mod)%MOD )); the } the } the } - inmax=Max (max,f_max[n][m]); themin=min (min,f_min[n][m]); the About } the voidmove_a (LL x) { thememset (b,0,sizeof(b)); thememset (SUM,0,sizeof(sum)); + LL now; - for(LL i=1; i<=n;i++){ thenow=i+x;Bayi if(now>N) { thenow%=N; the } -b[now]=A[i]; - } the for(LL i=1; i<=n;i++){ thesum[i]=sum[i-1]+B[i]; the } the}
NOIP Digital Games