首页 / 软件开发 / 数据结构与算法 / 算法题:UVA 11125 - Arrange Some Marbles (dp)
算法题:UVA 11125 - Arrange Some Marbles (dp)2014-04-20 csdn博客 accelerator_Problem HArrange Some MarblesInput: Standard InputOutput: Standard Outputyou are given some marbles of n different color. You have to arrange these marbles in a line. The marbles adjacent with same color form a group. In each group there can be 1 to 3 marble. Adjacent group should have different color and size. The first and last group also should have different color and size. You are given the number of each of these n marbles. You have count the number of ways you can arrange them in a line maintaining the above constraints. For example you have 4 red marbles and 4 green marbles. You can arrange them in the following 8 way - GGGRRGRR, GGRGGRRR, GGRRRGGR, GRRGGGRR, RGGRRRGG, RRGGGRRG, RRGRRGGG, RRRGGRGG.InputInput contains multiple number of test cases. The first line contain the number of test cases t (t<3000). Each of the next line contains one test case. Each test case starts with n (1 ≤ n ≤ 4) the number of different color. Next contains n integers. The i"th integer denotes the number of marble of color i. The number of marbles of any color is within the range 0..7 (inclusive). The color of the marbles arenumbered from 1 to n.OutputFor each test case output contains one integer in one line denoting the number of ways you can arrange the marbles.Sample Input Output for Sample Input62 3 32 4 42 6 63 3 4 53 4 5 64 2 3 4 5081217412341440