color, for n pots lined up in a straight line of the flower coloring. The color of the adjacent flowers is different, and the color used is exactly K . Ask a total of several coloring schemes (results except 10e9+7 take remainder). Problem Solving Ideas: First you can m m K C (M, k) and then by trying to discover, the first one has k Choice, second reason cannot be the same as the first one , only (k-1) (k-1) kx (K-1) ^ (n-1) k K Then there is a problem of repu
Test instructions: Give a string, where only F, A, n three letters, ask the least exchange how many times can make all a before all F.Solution: Greedy. First preprocessing how many F on the left side of each bit has a, for each a must be at least the left of the number of times to switch to the F number of its left, and for N to compare the number of F to the left and the number of right a, the small portion of the exchange to the other end of N. The answer to both cases is the final answer.Code
input
58 2 7) 3 11100
Sample output
Case 1:3case 2:0
Tips
first set of examples: The following 4 books bound together, binding 3 times, composed of 8 13
The second set of examples: only one book, no binding
How to solve the problem: we define dp[i] as the minimum number of steps to organize the first stacks of books into non-descending sequences. Defi
) { -T[p].next[id] = + +L; -++T[P].N; the } -p =T[p].next[id];Wuyi++i; the } - } Wu - intDfsintRT) { About inti; $ intSt =0; - - if(T[RT].N = =0) - return 2; A + for(i=0; i -; ++i) { the if(T[rt].next[i]) -St |=DFS (T[rt].next[i]); $ } the Switch(ST) { the Case 0: the return 3; the Case 1: - return 2; in Case 2: the return 1; the Case 3: About return 0; the default: the ret
141b-hopscotchLet's bust the "level" 0≤ i ≤106, with which assumedly the stone could hit. Let's find the minimal number of square on the. Then we can understand, how many squares there is on this level:one or both. Then we check with one or both ifs (if on this level, squares) if the stone is in corresponding square or not. If the stone is inside then output the answer. If we didn ' t find any square, where the stone is, output "-1".The official meaning is probably 6 levels, one to enumerate pa
[++cns]=Ss; return; } intt1=fnum-Nownum; Rep (I,nowpos,nn-t1+1){ intNss=ss+ (11)); Finds (Nn,fnum,nownum+1, i+1, NSs); }}voidCalcintNnintS) {//The total length is NN, and the state S is calculated in the position of 1, which exists in global pointer P "". cnp=0; Rep (I,1, nn) { intT= (11)); if((st) >0) {p[++cnp]=i; } }}voidinit () {CnS=0; CnP=0; Finds (N,2,0,1,0); MEM (DP,0); Rep (I,1, CnS) { intss=S[i]; Calc (N,SS); Rep (J,2, CnP) { if(g[p[1]][p[j]]=
1Because the first article did not write test instructions led to most of the problems of God has been completely unaware of what is said ... So we have to re-open an article to protect the peace ..."303A" test instructions: for the arrangement of three lengths of $n (nKonjac konjac cultivation of CF Orange name Program 2
; - if(Mark[u]) -nd[u].mx =0; - for(i=0; Ii) { Av =E[u][i]; + if(V! =FA) { theTMP = DFS (V, u) +1; - if(TMP >=nd[u].mx) { $ //find the fathest distance from p[*] to u theND[U].MX2 =nd[u].mx; thend[u].mx =tmp; the}Else if(tmp >nd[u].mx2) { theND[U].MX2 =tmp; - } in } the } the About //-1 means no P in the path the returnnd[u].mx; the } the + voidDFS2 (intUintFaintpmx) { - intI, V; the intTMP =Max (PMX, nd[u
1, CF #371 (Div. 2) C. Sonya and Queries map application, also available trie2, Summary: Start directly with the array traversal, decisive t a pitchTest instructions: Number of T, odd change 1, even change 0, then match with ask.#include #defineMax (A, b) a>b?a:b#defineF (I,A,B) for (int i=a;i#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineLL Long Longusing namespacestd;Const intn=110000, max=1000100; LL Cal (ll m) {intk=0; LL sum
)? ≠? (aJ,?bJ,?CJ).The next line contains a integer- q (1?≤? Q≤?100), denoting the number of the queries.Then followsQLines, containing space-separated, integers- ui and vi (1?≤? u i,? v i? ≤? N ). It's Guaranteed that ui? ≠? v I .OutputFor each query, print the answer-a separate line.Sample Test (s) input4 51 2 11 2 22 3 12 3 32 4 331 23 41 4Output210Input5 71 5 12 5 13 5 14 5 11 2 22 3 23 4 251 55 12 51 51 4Output11112NoteLet ' s consider the first sample.
The figure above shows the f
Write PPC recently
ProgramAfter repeated debugging procedures, I summarized some methods to improve the debugging efficiency.
1. First, you 'd better have a real PDA. The simulator runs much slower than the real PDA.
2. Recommended PDA controller professional. It is used to remotely control the PDA. It is placed on the desktop and set to start when the PDA is connected. You can view the screen on the PDA in real time and provide functions such as soft start, task management, file management,
You can go to CF to find the question.
Analysis process:
If it is an even number, it is directly equal to dividing by 2, for example, F (8) = f (4) = F (2) = F (1)
If it is an odd number, add 1 after dividing by 2 directly, for example, F (1) = f (0) + 1 = 0 + 1 = 1
It can be proved that the Left and Right numbers can be continuously divided by 2, and the formula is obtained: F (0) + x = x.
So what is X?
First, we can see through observation that as l
Input n a B k has n floors. The starting point of n floors cannot be reached at layer a and layer B. Assuming that the current position on layer x can reach layer y at each time. | x-y | Dp [I] [j] is the number of solutions that reach layer j for the I-th dp [I] [j] = sum (dp [i-1] [k]) | k-j | K that meets the condition is a continuous segment with prefix and optimization# Include CF 479E Riding in a Lift prefix and DP
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.