Nyoj_1273_ propaganda Wall

Source: Internet
Author: User
Tags time limit
/*
Propaganda wall
Time limit: Ms | Memory Limit: 65535 KB
Difficulty: 4

Describe

The ALPHA town is beautiful, the roads are neat and clean, and there are so many tourists to visit. The CBA mayor is preparing a series of propaganda on a wall 4*n the south of a road.
In order to unify the plan, the CBA mayor asks each propaganda column only to occupy the adjacent two squares position. But the road is divided by another road into about two paragraphs.
CBA mayor want to know, if each location is affixed to the propaganda column, left and right two paragraphs each have how many different posting scheme. For example: N=6,m=3, k=2, left,
There are 5 different posting schemes on the right.

Input
The first line: T means the following have T Group test data (1≤T≤8)
Next there are t-lines, three positive integers per line, N M K for the length of the road, and the beginning and width of the other road.
(1≤n, M≤1 000 000, 1≤k≤100000)
Output
Each set of test data, the output is one line: two integers, representing the left and right two different posting scenarios. As the total number of programmes
May be large, please output the result after modulo 997.
Sample input

2
6 3 2
5 3 2

Sample output

5 5
5 1

*/

State compression DP, very typical of a chestnut. Also want to say, with the scrolling array is better, we open the array almost explode.

#include <stdio.h> #include <string.h> #include <stdlib.h> const int col = 4;
int row;

int dp[900000][1<<4];
		void Dfs (int r,int c,int pre,int now) {if (C==col) {Dp[r][now] + = Dp[r-1][pre];
		Dp[r][now]%= 997;
	return;
		} if (C+1<=col) {DFS (r,c+1,pre<<1, (now<<1) | |);
	DFS (r,c+1, (pre<<1) | |, now<<1);
	} if (C+2<=col) {DFS (r,c+2, (pre<<2) |3, (now<<2) |3);
	}} int main () {int t,n,m,k;
	scanf ("%d", &t);
		while (t--) {scanf ("%d%d%d", &n,&m,&k);
		row = M-1;
		if (row<=0) {printf ("0");
			} else {memset (dp,0,sizeof (DP));
			dp[0][(1<<col)-1] = 1;
			for (int i=1;i<=row;i++) {DFS (i,0,0,0);
		} printf ("%d", dp[row][(1<<col)-1]);
		} row = n-m-K + 1;
		if (row<=0) {printf ("0\n");
			} else {memset (dp,0,sizeof (DP));
			dp[0][(1<<col)-1] = 1;
			for (int i=1;i<=row;i++) {DFS (i,0,0,0); } printf ("%d\n", dp[row][(1<<col)-1]);
}} 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.