Bzoj 1188 [HNOI2007] split game (SG function, game)

Source: Internet
Author: User

1188: [HNOI2007] Split game time limit:10 Sec Memory limit:162 MB
submit:733 solved:451
[Submit] [Status] [Discuss] Description

Cong Haruiri recently became obsessed with a game called splitting. The game's rules test: A total of n bottles, labeled 0,1,2.....n-1, the first bottle containing p[i] chocolate beans, two people take turns to pick beans, each round to choose 3 bottles. Marking is i,j,k, and to ensure I < J, J < = K and the first bottle of at least 1 chocolate beans, then this person from the first bottle to take a bean and put a bean in the J,k (J may be equal to K). If someone turns out to be unable to take the beans according to the rules, he will lose the game. The winner can take all the chocolate beans! The two people finally decided to take the beans by Cong, in order to get the final chocolate beans, Cong naturally want to win the game. He thought about it, found that in some cases, the first person must have a way to win, but he did not know whether there is a winning strategy for other situations, but also do not know how to take the first step. He decided to secretly consult the smart you, hoping you can tell him, given the first number of beans in each bottle to get all the chocolate beans, he also wants you to tell him how to take the first step, and in order to win, the first step how many kinds of ways? Assume 1 < N < = 21,p[i] < = 10000

Input

The first line of the input file is an integer t representing the number of groups of test data, followed by the T Group Test data (t<=10). The first row of each set of test data is the number of bottles N, and the next line has n a non-negative integer separated by spaces, indicating the number of beans in each bottle.

Output

For each set of test data, the output consists of two lines, the first behavior is separated by a space of 22 three integers, the first step should be selected to win the game, the number of the 3 bottles should be chosen i,j,k, if there are more than one set of solutions, then the output dictionary order the smallest group. If you can't win the game anyway, the output will be three-1 separated by a space of 22. The second line shows how many different ways to make sure that you win the game, the first step.

Sample Input2
4
1 0 1 5000
3
0 0 1
Sample Output0 2 3
1
-1-1-1
0Hintsource

Ideas

sg function, game

Constructs the SG function, takes the pawn position as the state, its successor is the J,K position. Enumerates the Ijk and accumulates tot according to the value of the SG function after operation.

True Magic < _ <

Code

1#include <cstdio>2#include <cstring>3 using namespacestd;4 5 Const intN = -;6 7 intN,a[n],sg[n],ans,tot;8 9 intDfsintx) {Ten     if(sg[x]!=-1)returnSg[x]; One     if(x==n)returnsg[x]=0; A     BOOLvis[10001]; -memset (Vis,0,sizeof(Vis)); -      for(inti=x+1; i<=n;i++) the          for(intj=i;j<=n;j++) -Vis[dfs (i) ^dfs (j)]=1; -      for(intI=0;; i++) -         if(!vis[i])returnsg[x]=i; + } -  + intMain () { A     intT; atscanf"%d",&T); -      while(t--) { -memset (sg,-1,sizeof(SG)); -ans=tot=0; -scanf"%d",&n); -          for(intI=1; i<=n;i++) inscanf"%d",&a[i]); -          for(intI=1; i<=n;i++)  to             if(a[i]&1) ans^=DFS (i); +          for(intI=1; i<=n;i++) -              for(intj=i+1; j<=n;j++) the                  for(intk=j;k<=n;k++) { *                     if((Ans^dfs (i) ^dfs (j) ^dfs (k)))Continue; $++tot;Panax Notoginseng                     if(tot==1) printf ("%d%d%d\n", I-1, J-1, K-1); -                 } the         if(!tot) printf ("-1-1 -1\n"); +printf"%d\n", tot); A     } the     return 0; +}

Bzoj 1188 [HNOI2007] split game (SG function, game)

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.