F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Necklace

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2299    Accepted Submission(s): 678


Problem Description
You are given a necklace consists of N beads linked as a circle. Each bead is either crystal or jade.
Now, your task is:
1.  Choose an arbitrary position to cut it into a chain.
2.  Choose either direction to collect it.
3.  Collect all the beads in the chosen direction under the constraint that the number of crystal beads in your hand is not less than the jade at any time.
Calculate the number of ways to cut meeting the constraint
 

Input
In the first line there is an integer T, indicates the number of test cases. (T<=50)
Then T lines follow, each line describes a necklace. ¡®C¡¯ stands for a crystal bead and ¡®J¡¯ stands for a jade bead. The length of necklace is between 2 and 10^6.
 

Output
For each case, print ¡°Case x: d¡± on a single line in which x is the number of case counted from one and d is the number of ways.
 

Sample Input
2 CJCJCJ CCJJCCJJCCJJCCJJ
 

Sample Output
Case 1: 6 Case 2: 8
 

Author
love8909
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-03 11:41:37, Gzip enabled