Topic Links:
https://vijos.org/p/1218
Main topic:
An n number of rings, divided into M block, the sum of the number within the block of 10, the last each plot value multiplicative, to find the maximum and minimum.
N (1≤n≤50) and M (1≤m≤9) are too small to be casually engaged.
Topic Ideas:
"Dynamic Planning"
Interval DP. Ring DP. A broken loop is a chain that complements a section of n at the back when the chain is made.
F[I][J] indicates that the number of previous i is divided into M-block maximum, g[i][j] is the minimum value. You need to enumerate from which point L begins to take n bits backwards.
Then enumerate the starting position of the current piece K.
by coolxxx//#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include < string> #include <iomanip> #include <map> #include <memory.h> #include <time.h> #include < stdio.h> #include <stdlib.h> #include <string.h>//#include <stdbool.h> #include <math.h> # Define MIN (a) < (b)? ( A):(B)) #define MAX (a) > (b) ( A):(B)) #define ABS (a) ((a) >0? ( A):(-(a))) #define LOWBIT (a) (a& (a)) #define SQR (a) ((a) * (a)) #define SWAP (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) # Define MEM (A, B) memset (A,b,sizeof (a)) #define EPS (1e-8) #define J #define MOD 1000000007 #define MAX 0x7f7f7f7f #defin
E PI 3.14159265358979323 #define N 104 using namespace std;
typedef long Long LL;
int cas,cass;
int N,m,lll,ans;
int a[n],sum[n];
int f[n][14],g[n][14];
int main () {#ifndef Online_judge//Freopen ("1.txt", "R", stdin);//Freopen ("2.txt", "w", stdout);
#endif int I,j,k,l,maxx,minn;
For (scanf ("%d", &cas); cas;cas--)For (scanf ("%d", &cas), cass=1;cass<=cas;cass++)//while (~SCANF ('%s ', s+1)) while (~SCANF ("%d", &n)) {Maxx
=0;minn=max;
scanf ("%d", &m);
sum[0]=0;
for (i=1;i<=n;i++) {scanf ("%d", &a[i]);
A[i+n]=a[i];
} for (i=1;i<=n+n;i++) sum[i]=sum[i-1]+a[i];
for (l=0;l<n;l++) {mem (f,0); mem (g,14);
for (i=1;i<=n;i++) {f[i+l][1]= ((Sum[i+l]-sum[l])%10+10)%10;
G[i+l][1]= ((Sum[i+l]-sum[l])%10+10)%10; For (J=2;j<=min (i,m); j + +) {for (k=j-1;k<i;k++) {F[i+l][j]=max (f[i+l][j],f[k+l][j-1]* ((sum[i+l]-
SUM[K+L])%10+10) (%10));
G[i+l][j]=min (g[i+l][j],g[k+l][j-1]* (((sum[i+l]-sum[k+l)%10+10)%10));
}}} Maxx=max (F[n+l][m],maxx);
Minn=min (G[n+l][m],minn);
} printf ("%d\n%d\n", Minn,maxx);
} return 0;
}
/*
//
//
*/