Topic: Given a 01 string, define H (s) to change all the "0" in S to "1", all "1" into "10", Σh^ai ("0") is H^m ("0") is the substring of which m∈[0,﹢∞)
Kneeling VFK ...
Make Si=h^i ("0")
The table will find Sn=s (n-1) +s (n-2) But the nature of this problem is not helpful for the moment we ignore this nature ... (it will be used somewhere in the back)
First we define the inverse transformation of h^-1 (s) to H (s), i.e., for each "1", if it is "0" then it becomes "1" or "0".
It can be found that if s contains "00" then S is not inverse transformation
Apparently S is the substring of the SM equivalent to H^-1 (s) is the substring of s (m-1)
Then the algorithm is very good to think
Each time we ask the Σs (AI) for an inverse transform, this operation is equivalent to all AI minus one
So what if an AI is 0?
We discuss:
If the i=1 must have a "1" in front of it to complete the inverse transformation, we might as well change the AI to 2, which is equivalent to adding a "1" to the front.
If a (i-1) is even then a (i-1) is apparently terminated with 0 (by Sn=s (n-1) +s (n-2)) so the "00" Output "NIE" appears in S
If a (i-1) is odd and >=5 due to s5= "10110101", all S (2k+1) (k>=2) are suffixed with "10101" (Sn=s (n-1) +s)
and "101010" inverse transformation 2 times after the emergence of "00", so this case directly output "NIE"
If a (i-1) =1 so a1+a0=a2 change A (i-1) to 2, delete the AI.
If a (i-1) =3 so a3+a0= "1010" =a2+a2, then A (i-1) and a (i) will be changed to 2.
So that we can all the 0 to eliminate the spicy ... And then you can subtract each AI by one.
When the n=1 algorithm is finished, output "TAK".
And then you're happy. WA dropped!
Why is it? We can measure this set of examples:
1
2
1 1
S= "11", this obviously can appear, but we inverse transformation after actually become "00"!
Why is it? Because the end of "1" can become "0" and can become "1"!
Since it can become "0" and "1" then this "1" will not cause S to appear in SM
Then we delete this "1" is not so spicy ...
In the same vein, if the end is 3 then we'll turn this 3 into 2.
What, you say 5? 5 is not able to answer "0" ah forget it = =
And then the question is done ... Oh, God, qaq.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 100100using namespace Std;int n;int a[m];bool Solve () {int I;while (n>1) {if (!a[1]) a[1]=2;if (a[n]==1) N--;else if (A[n] ==3) a[n]=2;for (i=n;i;i--) if (!a[i]) {if (a[i-1]==1) A[i-1]=2,a[i]=-1;else if (a[i-1]==3) A[i-1]=2,a[i]=2;elsereturn false;} int Temp=0;for (i=1;i<=n;i++) if (a[i]!=-1) a[++temp]=a[i];n=temp;for (i=1;i<=n;i++) a[i]--;} return true;} int main () {int t,i;for (cin>>t; T t--) {cin>>n;for (i=1;i<=n;i++) scanf ("%d", &a[i]);p UTS (Solve ()? " TAK ":" NIE ");} return 0;}
Bzoj 1141 POI2009 SLW