[Zjoi2011] Gift (gift) __pascal

Source: Internet
Author: User

2228: [Zjoi2011] Gift (gift)
Time Limit:10 Sec Memory limit:259 MB
Submit:32 solved:19
[Submit] [Status] [Discuss]
Description
Little White's birthday is coming, small blue decided to send a hand-made handicrafts to make their gifts different. Specifically, little blue has somehow produced a PXQXR block (composed of pqr small pieces of wood). But because the small blue craft is not fine, now this block some units small block is the question (has the crack, inside is the hollow and so on), such gift small blue is impossible to send out directly. So little Blue decided to dig a axaxb in this block of wood (that is, the required to be dug out of the rectangular block of two equal length of adjacent sides), of course, this block of wood can not contain the problem of small pieces of wood. In order for the block to contain more patterns, the small blue would like to pick out the maximum of 4ab values from all feasible solutions. But the small blue light detects in the block where has the problem to have exhausted the physical strength, as the small blue friend, you can help the small blue.
Input
Only one test data is included in each input file. The first line contains three positive integers separated by spaces, p,q,r. Then there is the PQ line, each containing r characters, each character can only be ' P ' (Poor) or ' N ' (Nice), indicating that the unit small block is problematic or no problem. Specifically, the z character of the 1+ (YP+X-P) line describes a small block of wood with coordinates (X,Y,Z). (1<=X<=P,1<=Y<=Q,1<=Z<=R)
Output
The output file contains only an integer that represents the 4ab value of the best scenario.
Sample Input
3 2 5
pnnnn
pnnnn
Nppnp
Pnnnp
Nnnnp
Ppnnp

Sample Output
24

"Data Range"
For 100% of the data, 0
HINT

Source
Day1

Meaning

This problem is not difficult, it synthesizes the scope of the family http://hi.baidu.com/hccz95/blog/item/10f7fff9533ba30609244df9.html and zoj1985 two questions

Refer to the procedure

/************************************************************** problem:2228 user:hccz95 language:pascal Result: Accepted time:6560 Ms memory:24028 KB ****************************************************************/uses math; {$r-,s-,q-} const MAXN = 150; Type Garr = array[0..maxn,0..maxn,0..maxn] of Char; var wid, Hei, Len, Ans:longint; C, L, R, stk:array[0..MAXN] of Longint; g:array[0..2] of Garr; f:array[0..MAXN,0..MAXN,0..MAXN] of Longint; function Get (n:longint): Longint; var i, Top:longint; Begin Top: = 0; stk[Top]: = 0; For I: = 1 to n did begin while (c[i] <= c[stk[top]) and (Top > 0) does Dec (top); l[i]: = i-stk[top]; Inc. (top); stk[Top]: = i; End Top: = 0; stk[Top]: = n + 1; For I: = n downto 1 does begin while (c[i] <= c[stk[top]) and (Top > 0) does Dec (top); r[i]: = stk[top]-i; Inc. (top); stk[Top]: = i; End Top: = 0; For I: = 1 to n does top: = Max (top, c[i] * (l[I ] + r[i]-1); Get: = top; End Procedure work (p, q, R:longint; var g:garr); var i, J, K:longint; Begin Fillchar (f, sizeof (f), 0); For I: = 1 to P does for j: = 1 to Q does for k: = 1 to R do if g[I [j] [k] = ' N ' then f[i] [j]: = Min (f[i] [j -1] [k-1], Min (f[i [j-1] [K], f[i] [j] [k-1])) + 1; for J: = 1 "q" for k: = 1 to R does begin for I: = 1 to P do c[i]: = f[I [j] [K]; Ans: = max (ans, get (p)); End End Procedure main; var i, J, K:longint; Begin READLN (WID, Hei, Len); For I: = 1 to Hei do with J: = 1 to Wid does begin for k: = 1 to Len do begin read (g[0 [i] [j]]); g[1 [j] [i] [K]: = g[0] [i] [j] [K]; g[2 [k] [i] [j]: = g[0] [i] [j] [K]; End READLN; End Ans: = 0; Work (HEI, wid, Len, g[0]); Work (WID, Hei, Len, g[1]); Work (Len, Hei, Wid, g[2]); Writeln (ANS * 4); End Begin main; End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.