ARC 081 D (discussion), E (DP), F (law. Maximum sub-rectangular deformation)

Source: Internet
Author: User

Test instructions: 2*n Square, known 1*2,2*1 Domino arrangement, now has 3 colors, ask the adjacent domino color to different dyeing scheme? n<=52.

The x is vertical and the y is horizontal. The former I-1 group staining scheme is res

Last group: Xi-1,xi XI There are two options, the last is two horizontal with two horizontal, then any one of the previous scheme, and finally the two transverse have 3 kinds of dyeing program. Other similar

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5E2+20;
const LL MOD=1E9+7;
int n;
Char A[n],b[n];
int main ()
{
	while (cin>>n)
	{
		scanf ("%s%s", a+1,b+1);
		ll Ans=1,i;
		if (a[1]==b[1])
			ans*=3,i=2;
		else 
			ans*=6,i=3;
		for (; i<=n;i++)
		{
			if (A[i]==b[i])
			{
				if (a[i-1]==b[i-1])
					ans= (ANS*2LL)%mod;
			}
			else
			{
				if (a[i]==a[i-1]&&b[i]==b[i-1])
				{
					if (a[i-2]==b[i-2])
						ans= (ANS*2LL)%mod;
					else
						ans= (ans*3ll)%mod;
		}} cout<<ans<<endl;
	}
	return 0;

Test instructions: Given the string s, if the string T is not a sub-sequence of S, then the T is called the legal string of S.
|s|<=2e5, find the smallest dictionary order in the S legal string.

Set Dp[i][c]: suffix I, the shortest legal string beginning with C.
Dp[i][c]=min (Dp[i+1][k]+1] S[i]==c
DP[I][C]=DP[I+1][C] S[i]!=c

Nxt[i][c] A character that records the next state of Dp[i][c].
Find Dp[1][c] The shortest length of c. Continuously outputs the solution via NXT.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5E2+20;
const LL MOD=1E9+7;
int n;
Char A[n],b[n];
int main ()
{
	while (cin>>n)
	{
		scanf ("%s%s", a+1,b+1);
		ll Ans=1,i;
		if (a[1]==b[1])
			ans*=3,i=2;
		else 
			ans*=6,i=3;
		for (; i<=n;i++)
		{
			if (A[i]==b[i])
			{
				if (a[i-1]==b[i-1])
					ans= (ANS*2LL)%mod;
			}
			else
			{
				if (a[i]==a[i-1]&&b[i]==b[i-1])
				{
					if (a[i-2]==b[i-2])
						ans= (ANS*2LL)%mod;
					else
						ans= (ans*3ll)%mod;
		}} cout<<ans<<endl;
	}
	return 0;

Test instructions: n*m matrix, each grid is black or white. OP: Reverses the color of a row or column (Black to white, white to black)
N,m<=2e3,op use the number of times can you get the largest total sunspot rectangle area?


The maximum number of OP times per row (op Two for a row equals not done).
Rule: 2*2 Small Rectangle if the initial 1 or 3 black, then no matter how to invert the 2*2 rectangle is not all black.

Then the last answer if it is an S rectangle, then any of the 2*2 sub-rectangles of s contains an even number of blacks.
Such s must be able to be filled, first: Do column inversion to turn the first line of S into full black
Because of arbitrary inversion, the parity of the Black block in the 2*2 rectangle is constant, so the second behavior is all 0, and the 3rd line is all 1 ... On the left line of the 0 row transform.

If the 2*2 sub-rectangle contains an even number of black sets to 1, then the problem becomes the maximum rectangular area of all 1, and the monotone stack can be solved.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2E3+20;
const int m=22;
int a[n][n];
string S;
int b[n],h[n];


int main ()
{
	int n,m;
	while (Cin>>n>>m)
	{for
		(int i=0;i<n;i++)
		{
			cin>>s;
			for (int j=0;s[j];j++)
				a[i][j]=s[j]== ' # '? 1:0;
		}
		int Ans=max (n,m);
		for (int i = 0, i < n; ++i)
	    {for
	    	(int j = 0; j < m; ++j)
	    	{	
			if (i&&! ( A[I-1][J+1]^A[I][J]^A[I-1][J]^A[I][J+1]) h[j]++;
            		else h[j]=1;
		}
			int t=0;
			for (int j=0;j<=m-1;j++)
			{
				while (T&&h[b[t-1]]>=h[j])
				{
					int x=b[--t];
					if (t==0) Ans=max (ans, (j+1) *h[x]);
					Else Ans=max (ans, (j-b[t-1]) *h[x]);
				}
				b[t++]=j;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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.