Portal:1400 sequence decomposition sequence decomposition
Base time limit: 1s space limit: 131072KBKb131072 KB 1 Second space limit: 131072 KB score: 40 4-level algorithmic questions 1 -Second space limit:131072 KB score : Difficulty:4-level algorithm problem
The knife and Broadsword are twin brothers. Today they play an interesting game. The broadsword gives the knife a sequence of integers of length n. The knife tries to break down the sequence into two sub-sequences with a length of N/2.
These two sub-sequences must meet the following two conditions:
1. They cannot overlap each other.
2. They want exactly the same.
If the knife can be broken down successfully, the broadsword will give the knife some sweets.
However, this problem is too difficult for a knife. He wants to ask you to help.
Input
The first line gives a T, which represents the T-group data. (1<=t<=5) The next set of data, enter a total of 2 rows. The first line contains an integer n (2<=n<=40 and even). The second line gives n integers a[0],a[1],a[2],..., a[n-1] represents the series of knives prepared by a machete. ( -1,000,000,000<=a[i]<=1,000,000,000) The first line gives a T, which represents the T-group data. (1<=t<=5)
Next, enter a total of 2 rows for each set of data.
The first line contains an integer n (2<=n<=40 and even).
The second line gives n integers a[0],a[1],a[2],..., a[n-1] represents the series of knives prepared by a machete. ( -1,000,000,000<=a[i]<=1,000,000,000)
Output
If the knife can complete the game, output "good job!!" (not including quotation marks), otherwise output "what a pity!" (not including quotation marks). If the knife can complete the game, output "good job!!" (not including quotation marks), otherwise output "what a pity!" (not including quotation marks).
Input example
241 1 2 261 2 3 4 5 62
4
1 1 2 2
6
1 2 3 4 5 6
Output example
Good job!! What a pity! Good job!!
What a pity!
Paste Code
1#include <bits/stdc++.h>2 using namespacestd;3 inta[ -], N, x[ -], y[ -];4 BOOLDfsintIintJintk) {5 BOOLRes;6 if(k>n)return true;7 if(i>n>>1){8 returnA[k]==x[j]?y[j]=a[k], DFS (i, j+1, K +1):false;9 }Ten if(j>n>>1){ One returnA[k]==y[i]?x[i]=a[k], DFS (i+1, J, K +1):false; A } - if(i==j) { -x[i]=A[k]; the if(Dfs (i+1, J, K +1))return true; -y[j]=A[k]; - returnDFS (i, j+1, K +1); - } + if(i>j) { -res = X[j]==a[k]?y[j]=a[k],dfs (i, j+1, K +1):false; + if(RES)returnRes; A returnX[i]=a[k],dfs (i+1, J, K +1); at } - if(j>i) { -res = Y[i]==a[k]?x[i]=a[k],dfs (i+1, J, K +1):false; - if(RES)returnRes; - returnY[j]=a[k],dfs (i, j+1, K +1); - } in } - intMain () { to //freopen ("in", "R", stdin); + intT; -scanf"%d", &T); the while(t--){ *scanf"%d", &N); $ intres=0;Panax Notoginseng for(intI=1; i<=n; i++) scanf ("%d", a+i), res^=A[i]; - if(res) { thePuts"What a pity!"); + Continue; A } thex[1]=a[1]; +Puts (DFS (2,1,2)?"Good job!!":"What a pity!"); - } $ return 0; $}
51NOD 1400 Sequence decomposition