The problem of stochastically allocating redundant components to increase the system lifetime is an important topic of reliability. An optimal redundancy allocation is proposed, which maximizes the expected lifetime of a reliability system with subsystems consisting of components in parallel. The constraints are minimizing the total resources and the sizes of subsystems. In this system, each switching is independent with each other and works with probability p. Two optimization problems are studied by an incremental algorithm and dynamic programming technique respectively. The incremental algorithm proposed could obtain an approximate optimal solution, and the dynamic programming method could generate the optimal solution.