topic:
analysis:
This question lies in the difficulty:
Every time the transfer, to record a lot of points to be flipped, but also to determine who their next fa yes.
So to change my ideas: the transition from state to terminate 0 state (initial state), backwards to.
Suppose now to the penultimate i seconds, then flipped a light from inside the i ~ ans time he is been going to jump up and affect other lamps, jump time i, it may be pretreated at: FA [i] [ j] i represents the lamp after step j can be varied to jump state
When each transfer, just enumerate lamp, XOR array can quickly know the fa penultimate second state i + 1.
An update to the initial state 0, direct output now is the inverse of the first few seconds can be.
Because even recording time, so dp to open two-dimensional.
Note: If a point has been passed to the root node, then the state will not become a! !
#include<bits/stdc++.h> using namespace std; #define N 18 #define ri register int int ff[N],fa[N][N],dp[N][1<<N],n,goal=0,x; int main() { freopen("decoration.in","r",stdin); freopen("decoration.out","w",stdout); scanf("%d",&n); ff[1]=0; for(ri i=2;i<=n;++i) scanf("%d",&x),ff[i]=x; for(ri i=1;i<=n;++i) scanf("%d",&x),goal<<=1,goal+=x; for(ri i=1;i<=n;++i){ fa[i][0]=(1<<(n-i)); int pre=ff[i]; for(ri j=1;j<=n;++j){ if(pre) fa[i][j]=fa[i][j-1]^(1<<(n-pre));// If the root node has been reached 1, and would not jump up the else FA [I] [J] = FA [I] [J- 1 ]; pre = FF [pre]; } } DP [ 0 ] [Goal ] = . 1 ; for (RI T = 0 ; T <= n-; ++ T) { IF (DP [T] [ 0 ]) {the printf ( " % D \ n- " , T); return 0 ;} for ( J = RI 0 ; J <( . 1 << n-); ++ J) IF (DP [T] [J]) { DP [T + . 1 ] [J] =1; for(ri k=1;k<=n;++k) dp[t+1][j^(fa[k][t])]=1; } } return 0; } /* 7 1 1 2 2 3 3 0 1 1 1 0 0 1 3 7 1 1 2 2 3 3 1 1 1 1 0 0 1 3 8 1 1 2 4 2 4 6 0 0 1 0 1 1 0 1 3 1 1 0 1 1 */