party lamps(dfs优化+规律枚举)

Problem description:

To brighten up the gala dinner of the IOI'98 we have a set of N coloured lamps numbered from 
1 to N. The lamps are connected to four buttons: 
button 1 -- when this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON. 
button 2 -- changes the state of all the odd numbered lamps. 
button 3 -- changes the state of all the even numbered lamps. 
button 4 -- changes the state of the lamps whose number is of the form 3K+1 (with K >= 0), i.e., 1,4,7,... 
There is a counter C which records the total number of button presses. 
When the party starts, all the lamps are ON and the counter C is set to zero. 

You are given the value of counter C and information on the final state of some of the lamps. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.

汉化:

为了让IOI'98的晚宴更加精彩,我们有一套编号为的N色灯。

1到N。灯与四个按钮相连:

按钮1——当按下此按钮时,所有的灯都会改变其状态:打开的灯关闭,关闭的灯打开。

按钮2——改变所有奇数灯的状态。

按钮3——改变所有偶数灯的状态。

按钮4——改变灯的状态,灯的编号形式为3K+1(k>=0),即1,4,7,…

有一个计数器C记录按钮按下的总数。

聚会开始时,所有的灯都亮着,计数器C调零。

 您将获得计数器C的值和一些灯的最终状态信息。编写一个程序来确定n个灯的所有可能的最终配置,这些配置与给定的信息一致,无需重复。

Input:

Your program is to read from standard input. The input contains four lines, describing the number N of lamps available, the number C of button presses, and the state of some of the lamps in the final configuration. 

The first line contains the number N and the second line the final value of counter C. The third line lists the lamp numbers you are informed to be ON in the final configuration, separated by one space and terminated by the integer -1. The fourth line lists the lamp numbers you are informed to be OFF in the final configuration, separated by one space and terminated by the integer -1. 

The parameters N and C are constrained by: 
10 <= N <= 100 
1 <= C <= 10000 
The number of lamps you are informed to be ON, in the final configuration, is less than or equal to 2.The number of lamps you are informed to be OFF, in the final configuration, is less than or equal to 2.

汉化:

您的程序将从标准输入中读取。输入包含四行,描述可用灯的数量n、按钮按下的数量c以及最终配置中某些灯的状态。

第一行包含数字n,第二行包含计数器c的最终值。第三行列出在最终配置中通知您要打开的灯号,用一个空格分隔并以整数-1结束。第四行列出了在最终配置中通知您要关闭的灯号,用一个空格分隔并以整数-1结束。

 参数n和c受以下约束:

10<=n<=100

1<=c<=10000

在最终配置中,通知您要打开的灯的数量小于或等于2。在最终配置中,通知您要关闭的灯的数量小于或等于2。

Output:

Your program is to write to standard output. The output must contain all the possible final configurations (without repetitions) of all the lamps. There is at least one possible final configuration. Each possible configuration must be written on a different line. Each line has N characters, where the first character represents the state of lamp 1 and the last character represents the state of lamp N. A 0 (zero) stands for a lamp that is OFF, and a 1 (one) stands for a lamp that is ON. Configurations should be listed in binary ascending order.

汉化:

您的程序将写入标准输出。输出必须包含所有灯的所有可能最终配置(无重复)。至少有一个可能的最终配置。每个可能的配置都必须写在不同的行上。每行有n个字符,其中第一个字符表示灯1的状态,最后一个字符表示灯n的状态。0(零)表示灯关闭,1(一)表示灯打开。配置应按二进制升序列出。

Sample Input

10
1
-1
7 -1

Sample Output

0000000000
0101010101
0110110110


分析:
1.题意理解概括与规律探寻详见博文:https://blog.csdn.net/wmn_wmn/article/details/7382242
2.详细分析见博文:https://blog.csdn.net/ly59782/article/details/52252329
原文地址:https://www.cnblogs.com/dragondragon/p/11250475.html