# 洛谷 加分二叉树

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 #include #include #include #include #include #include #include using namespace std; int n; struct re{     int i;     string s;     re(){             }     re(int i,string s){         this->i=i;         this->s=s;     }     re operator = (const re r){         this->i=r.i;         this->s=r.s;         return *this;     } }f[32][32]; int scores[35]; string construction(int num){     string s="";     while(num!=0){         s.insert(0,1,'0'+num%10);         num/=10;     }     s+=' ';     return s; } re dfs(int l,int r){     if(l==r)return re(scores[l],construction(l));     if(l>r)return re(1,"");     if(f[l][r].i!=0)return f[l][r];     int mm=0;     string s;     for(int i=l;i<=r;i++){         re re1=dfs(l,i-1);         re re2=dfs(i+1,r);         if(mm>n;     for(int i=1;i<=n;i++)cin>>scores[i];     re re1=dfs(1,n);     cout<

# 洛谷 【模板】KMP字符串匹配

 1234567891011121314151617181920212223242526272829303132333435363738394041 #include #include #include #include #include using namespace std; int _next[10000]; void buildNext(char * P){     int m=strlen(P),j=0;     int t=_next[0]=-1;     while(j

# KMP算法经典代码

 12345678910111213141516171819202122 int _next[10000]; void buildNext(char * P){     int m=strlen(P),j=0;     int t=_next[0]=-1;     while(j

# 洛谷 拼数

 12345678910111213141516171819 #include #include #include using namespace std; bool cmp(string & s1,string & s2){     return s1+s2>s2+s1; } int main(){     int n;     cin>>n;     string s[20];     for(int i=0;i>s[i];     }     sort(s,s+n,cmp);     for(int i=0;i

# 循环移位(Cycle)

### Description

Cycle shifting refers to following operation on the sting. Moving first letter to the end and keeping rest part of the string. For example, apply cycle shifting on ABCD will generate BCDA. Given any two strings, to judge if arbitrary times of cycle shifting on one string can generate the other one.

### Input

There m lines in the input, while each one consists of two strings separated by space. Each string only contains uppercase letter ‘A’~’Z’.

### Output

For each line in input, output YES in case one string can be transformed into the other by cycle shifting, otherwise output NO.

### Example

Input

AACD CDAA
ABCDEFG EFGABCD
ABCD ACBD
ABCDEFEG ABCDEE


Output

YES
YES
NO
NO


### Restrictions

0 <= m <= 5000

1 <= |S1|, |S2| <= 10^5

Time: 2 sec

Memory: 256 MB

### 限制

0 ≤ m ≤ 5000

1 ≤ |S1|, |S2| ≤ 10^5