Original question:
Critical Mass
During the early stages of the Manhattan Project, the dangers of the new radioctive materials were not widely known. Vast new factory cities were built to manufacture uranium and plutonium in bulk. Compounds and solutions of these substances were accumulating in metal barrels, glass bottles and cardboard box piles on t He cement oors of store rooms. Workers didn't know that the substances they were handling could result in sickness, or worse, an explosion. The O cials who new the danger assumed, they could ensure safety by never assembling any amount close to the critical Mass estimated by the physicists. But mistakes were made. The workers, ignorant of the the dangers, often
Did not track these materials care-fully, and in some cases, too much material was stored together {a accident was Waiti Ng to happen. Fortunately, the dangers were taken seriously by a few knowledgeable physicists. They drew up guidelines in the store the materials to eliminate the danger of critical mass accumulations. The system for handling uranium is simple. Each uranium cube is marked \ U ". It is to be stacked
With lead cubes (marked \ L ") interspersed. No more than, uranium cubes could is next to each and on a stack. With the-simple system, a potential for the uranium reaching critical mass (three stacked next to all other) was avoided . The second constraint is and no more than thirty cubes can being stacked on top of all other, since the height of the Stora The GE Hostel can only be accommodate that many. One of the physicists was still is completely satis ed with this solution. He felt that a worker, not
Paying attention or not trained with the new system, could easily cause a chain reaction. He posed the Question:consider a worker stacking the radioactive cubes and non radioactive cubes at random on top of each Other to a height of n cubes; How many possible combinations is there for a disaster to
Happen?
For example, say the stack is of size 3. There is one-on-the-stack-to-reach critical mass {if all-three cubes is radioactive.
1:uuu
However, if the size of the stack is 4, then there is three ways:
1:uuul
2:luuu
3:uuuu
Input
The input is a list of integers on separate lines. Each integer corresponds to the size of the stack and
is always greater than 0. The input is terminated with a integer value of 0.
Output
For each stack, compute the total number of dangerous combinations where each cube position in the
Linear stack can either is \ L "for leads, or \ U" for uranium. Output your answer as a single integer on
A line by itself.
Sample Input
4
5
0
Sample Output
3
8
Effect:
There are plenty of boxes with uranium (denoted by U) and lead (denoted by L). Requires n (n≤30) boxes to be placed in a row, but at least 3 U put together, how many kinds of methods? For example, N=4, 5, 30 o'clock the answers are 3, 8, and 974791728, respectively.
#include <bits/stdc++.h> using namespace std;//fstream in,out; int n; int f[31]; int Power
TWO[31];
int main () {Ios::sync_with_stdio (false);
Powertwo[0]=1;
for (int i=1;i<=30;i++) powertwo[i]=powertwo[i-1]*2;
f[0]=f[1]=f[2]=0;
F[3]=1;
for (int i=4;i<=30;i++) {int tmp=0;
for (int j=2;j<=i-2;j++) tmp+=powertwo[i-4]-powertwo[i-j-2]*f[j-2];
F[I]=TMP+POWERTWO[I-3];
} while (Cin>>n,n) {cout<<f[n]<<endl;
} return 0; }
Answer:
Lrj Small white Book on the example, a very good topic, answer from the book. The
sets the answer to f (n). Since there are 3 u put together, it can be classified according to the position of these 3 U-pairs, according to the previous experience, according to the "Leftmost 3 U" position classification. Assuming the 3 boxes of I, i+1 and I+2, the first i-1 box cannot have 3 U-put together. Set N Box "No 3 U put together" scheme number is g (n) =2^n-f (n), then the scheme of the first i-1 box has g (i-1) species. The back of the N-i-2 box can be casually selected, there are 2 n-i-2 species. According to the principle of multiplication and the principle of addition, unfortunately, this reasoning is flawed. Even if the first i-1 box does not appear inside 3 U, it is still possible to compose 3 U with I, i+1 and i+2. The correct method is to force the first i-1 box (if present) to put L, then the I-2 box inside cannot appear continuous 3 U. Thus, the boundary is F (0) =f (1) =f (2) =0g (0) =1,g (1) =2,g (2) = 4. Note that the 2 n-3 in the above formula corresponds to the case of I=1.