#113. Production of "Uer #2" mobile phone

Source: Internet
Author: User

Links: http://uoj.ac/problem/113

because of the development of telecommunication technology, everyone can connect with each other by mobile phone. A telecoms big guy recently wanted to make a large number of handsets, but it was too slow to produce a single platform from the production line, so he came up with a way to get the phone to replicate itself. So he added a built-in function fork () to the phone. Mobile phone Program If you call this function, then the phone will produce a completely identical phone (including the program running state), and its own function return value is One, the function return value for the new phone isxx, and both phones continue to execute the program. (Note boldface content) when initially, there is only one phone. Then the big guy lets the phone calculate the expression like this: fork ()<op> fork () <op> ... <op>fork () where<op> is a two-dollar operator for && or | |in one of the. Example: Fork ()&& fork () | | Fork () && fork () && fork () | |Fork () Two operations are left-associative, andPriority ratio of && | |high, so the expression above is equivalent to: (Fork ()&& fork ()) | | (fork () && Fork ()) && Fork ())) ||fork () for expression a&& B, the hand calculates the value of a first, if thexxThen do not calculate the value of B (because it is important, so say two times, please note that the value of B is not calculated here), the expression value isxxOtherwise, the value of B is computed and its value is used as the value of the expression. For an expression a|| B, the hand calculates the value of a first, if the OneThen do not calculate the value of B (because it is important, so say two times, please note that the value of B is not calculated here), the expression value is OneOtherwise, the value of B is computed and its value is used as the value of the expression. After the calculation of the expression, the big man made a staggering number of mobile phones, the human finally opened the finger-scale industrial manufacturing door. 100 million years later, an archaeologist investigated the incident. He gets the expression that the big guy lets the cell phone calculate. He wanted to know how many cellphones the big guy made. (including the initial cell phone) you can better understand test instructions by referring to the sample interpretation. Input format first line a positive integer nn that represents the number of fork () in an expression. Next line n?1n?1A string separated by spaces, each string is "&&" or "| |, which in turn represents the operator in the corresponding position in the expression. Output format one line, an integer represents the number of phones manufactured, you only use the output answer to998244353998244353(7X -X223+ -X -X223+1, a prime number) after the modulo result. Sample One input2&&Output3explanation co-production -mobile phone, the process is as follows: OneMobile phone start Computing fork () &&Fork (). Section OneThe mobile phone starts to calculate fork (), resulting in the first Amobile phone. Section OneDesk and section AThe fork () calculation is completed, OneStation back OneThe AStation backxx. Section OneCell phone because the fork () return value is One, the fork () to the right of the fork () && fork () is started, resulting in the first -mobile phone. Section ACell phone because the fork () return value isxx, the fork () && fork () value isxx(skipping the calculation of the right fork), the program ends. Section OneDesk and section -The fork () calculation is completed, OneStation back OneThe -Station backxx. Section OneCell phone because the fork () return value is One, the fork () && fork () value is One, the program ends. Section -Cell phone because the fork () return value isxx, the fork () && fork () value isxx, the program ends. Sample two input6&& | | && && | |Output thelimit and contract test point number size of nn1n=1n=12N≤5n≤5345N≤100n≤ -678N≤100000n≤1000009Tentime limit: 1s1s space limit: 256MB
Problem Dry

Understand test instructions First:

  Gives a logical operation formula (including several unit fork () and logical operator).

Because of the priority problem, we'll start with the word "| |" . Divide the boundaries into groups (with ' && ' connections between different fork () within each group)

Each time the fork () is run, it can produce another cell phone (note that they are not on the same world line, and they do not affect each other), and the newly generated phone is one on the fork () of the birth position (i.e. the newly generated cell phone) into the next group.

Go into some more:

Each cell phone can be copied only in the current group, and it produces the phone into the next set of replications. (Of course there was only one cell phone at the beginning, and then, slowly increasing).

#include <cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>using namespacestd;#defineMOD 998244353Queue<int>Q;intn,tot1,tot0,f[100009],cnt;Chara[100009],c,cc;intMain () {scanf ("%d",&n);//scanf ("%c", &c);     for(intI=1; i<n;i++) {scanf ("%c",&c); scanf ("%c%c",&c,&cc); A[i]=C; } tot1=1;  for(intI=1; i<n;i++)    {        if(a[i]=='&') tot1++; Elsef[++cnt]=tot1,tot1=1; } f[++cnt]=tot1; Long Longans1=1, ans0=f[1];  for(intI=2; i<=cnt;i++) {ans1= (ANS1+ANS0)%MOD; ANS0= (F[I]*ANS0)%MOD; } cout<< (ANS1+ANS0)%MOD; return 0;}
Code

#113. Production of "Uer #2" mobile phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.